From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

User Events vs. Queues vs. Notifiers?


@SteveChandler wrote:

I have a very general question.

 

Are there any guidelines on when to use user events vs a queue or a notify?

 

More specifically is there something you couldn't do if user events did not exist in LV?


Queues for "many to one"-operations, as writing to a serial port.

Events for "one to many"-operations, as callback events, you might have many actors.

 

If you have a process signalling it's done with a user event to 4 listener processes, you could ofcourse solve it through polling a status from a AE or peeking at a queue, but is it good design?

 

I think someone said all functions can be realized with loops and stacks, that doesn't mean we should limit us to that. 🙂

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 11 of 17
(3,840 Views)

If you have a process signalling it's done with a user event to 4 listener processes, you could ofcourse solve it through polling a status from a AE or peeking at a queue, but is it good design?


You can more naturally mimic a User Event with an array of queues.  Enqueuing a message to the array sends a copy to each listener.  

0 Kudos
Message 12 of 17
(3,822 Views)

@drjdpowell wrote:

If you have a process signalling it's done with a user event to 4 listener processes, you could ofcourse solve it through polling a status from a AE or peeking at a queue, but is it good design?


You can more naturally mimic a User Event with an array of queues.  Enqueuing a message to the array sends a copy to each listener.  


Good point. Still, it's a RGC (Rube Goldberg Code) construct. 🙂 

 

In the case of many to many, i think events are better than queues, so if in doubt, use events. 😉

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 13 of 17
(3,797 Views)

@Intaris wrote:

@SteveChandler wrote:

More specifically is there something you couldn't do if user events did not exist in LV?


Yeah.  Have a really neat and tidy asynchronous system up and running with tidy code.

 

As soon as your asynchronous process has it's own UI, User Events are the way to go.  I usually have a single event structure firing off a queue or notifiers as required to a consumer loop for updating UI and other things.

 

I love User Events and find them optimal for most inter-process communications.  Of course some applications require queues or notifiers (Like periodic checking of "Did the user quit this operation" actions) but per default, I go with user events.

 

Shane.


I have pretty much gone the user event route exclusively also. There are just too many benefits, and not enough drawbacks for me not to. On RT I find benefits, but where user events really begin to shine are within GUIs. The fact that loops can register for events they care about and all the queue creation for a single message to be copied to these different processes is abstracted from the programmer is a great time saver. It makes dynamic launching of different windows seemless -- you don't have to keep adding a queue to a list every time a new screen is opened; just register for the event that is needed and the rest is taken care of.

 

Another benefit of user events is, if no one is registered for an event, that event gets thrown away. This is my favorite feature of user events. What happens if you have a queue and no one is "listening"? Memory leak. User event, no one is listening? No problem. Let me give an example. I had an application that had about 18 subpanels on 3 different screens. I was constantly checking which screen was being shown and depending on which screen was open, I would queue up data to those sub panels. What a nightmare. Another option using queues was to have all screens running all the time and just hide them and show them. That way they were still dequeuing their elements in the background all the time. Eh, too much unneeded overhead. Enter User Events. When a window opens, it registers and gets data. When it closes, it unregisters. My main loop just spit out data all the time, it didn't care who was listening. User events decouple the sender and the receiver.

 

It should be noted, this type of behavior can be coded using native LabVIEW queues, and although I haven't looked into it extensively, I believe that's what the JAMA architecture does. However, since User Events already provide this functionality, I prefer to use them. I just hope that NI starts incorporating more of these concepts into their advanced training courses rather than just describing how "you can message back to your producer loop from your consumer in a producer consumer architecture."

 

One drawback (if it can be called that) is the command pattern is all but useless with this method. So, if you have been digging into the Actor framework, that concept won't translate well. This is due to the fact that multiple loops can get the same message. If a logging loop and a TCP loop both get the "xyz data" message and that message can only have one action associated with it, as the command pattern defines, well you're out of luck.

 

My .02. Yikes, that was longer than I thought it would be.

 

And to the question asked by the user who resurected this thread "Is a queue a superset of the notifier, in that it can stack up events?"

 

A notifier is basically a single element queue. In fact, one of my coworkers got an error while using a notifier and in the error description it talked about queues! 

Message 14 of 17
(3,788 Views)

 


      You can more naturally mimic a User Event with an array of queues.  Enqueuing a message to the array sends a copy to each listener.  


Good point. Still, it's a RGC (Rube Goldberg Code) construct. 🙂 


Well, under the hood User Events actually do involve an array of a type of queue (the Event Registration Refnums).  Understanding this is helpful in understanding User Events.  And if  one desired a User Event-like system (with some feature not satified by User Events) then you would have to have an array of <something> in there somewhere.

Message 15 of 17
(3,767 Views)

@for(imstuck) wrote:

A notifier is basically a single element queue. In fact, one of my coworkers got an error while using a notifier and in the error description it talked about queues! 

I suspect Notifiers are built on single-element queues, but there must be extra features built on top to allow for "wait on next notification".  

0 Kudos
Message 16 of 17
(3,765 Views)

Here's a post where AQ (who authored the Queue primitives) talks about their relation to user events:

http://lavag.org/topic/13435-queue-and-concurrency/#entry80638

 

and to notifiers:

http://lavag.org/topic/13435-queue-and-concurrency/#entry80660

Message 17 of 17
(3,744 Views)