LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

At what point does an even get removed from an event queue?

Solved!
Go to solution

If I create an event and then register it using a single register event node, I can then wait on that event in two separate loops, both using the same registration refnum, as long as each loop is actively waiting at the event structure, both loops will receive the event (usually).

 

I did not expect this.  I expected only one loop to ever receive the event, whichever was the first to wait for it, similar to how regular queues work.  However, most of the time, both loops receive it except in cases where presumably the OS interrupts the execution enough to cause one loop to execute significantly sooner than the other enable it to consume the event while the other misses it

 

If I delay one of the loops slightly, it will never receive the event as expected as the non-delayed one always consumes the queued event well before the delayed one can.

 

So at what point is an event actually removed from the event queue and why are multiple event structures able to receive the same event without having to use two separate registration nodes?



I saw my father do some work on a car once as a kid and I asked him "How did you know how to do that?" He responded "I didn't, I had to figure it out."
0 Kudos
Message 1 of 9
(4,397 Views)

Events should work more like notifiers in the sense that they broadcast the event to all tasks registered for the event. One thing that I have seen in the past is behavior can get a bit strange if you have two event structures registered for the same event in the same block diagram. This is the only time I have seen missed events. When I have used the event structures in separate VIs I have never had a problem nor have I ever missed an event.

 

It is generally recommended to only have a single event structure in a VI. It can be safe provided they do not register for the same events. However, I error on the safe side and limit a VI to a single event structure.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 2 of 9
(4,360 Views)

@blackburnite wrote:

If I create an event and then register it using a single register event node, I can then wait on that event in two separate loops, both using the same registration refnum, as long as each loop is actively waiting at the event structure, both loops will receive the event (usually).


You are technically in no-man's land here.  DO NOT FORK THE REGISTRATION.  If you do, there is no telling what mess will happen, as you have discovered.  You should have a registration for each Event Structure.  Then each Event Structure will have its own queue.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 9
(4,350 Views)

Yes, definitely.  I wouldn't do that in any code that was actually getting used.  It's more of a curiosity as I didn't actually know what would happen so tried it in a test VI and got an unexpected result.



I saw my father do some work on a car once as a kid and I asked him "How did you know how to do that?" He responded "I didn't, I had to figure it out."
0 Kudos
Message 4 of 9
(4,341 Views)

I've never had an issue with multiple event structures registered to the same event as long as they are using their own separate registration and not forking the same registration wire.

 

As you said, all tasks registered to an event should get it, one-to-many, which does happen.  But a single event registration *should* produce a single event queue which when "dequeued" by an event structure should make that event no longer accessible.

 

But what I'm seeing is that a single event is able to be "dequeued" from a registration queue more than once if multiple event structures, both using the same event registration refnum happen to execute at nearly the same time.



I saw my father do some work on a car once as a kid and I asked him "How did you know how to do that?" He responded "I didn't, I had to figure it out."
0 Kudos
Message 5 of 9
(4,337 Views)
Solution
Accepted by topic author blackburnite

Take a peek at this thread and the one linked therein:

 

https://forums.ni.com/t5/LabVIEW/Sub-VIs-One-Reg-events-to-rule-them-all/m-p/4149499#M1197037

 

Specifically my post here:

https://forums.ni.com/t5/Actor-Framework-Discussions/Stopping-multiple-helper-loops-with-one-user-ev...

 

Basically, it seems to be removed when the case finishes executing.

Message 6 of 9
(4,331 Views)

That's what I thought initially as well and had tested it by delaying the completion of the first event structure to execute but that did not result in the second event structure also receiving the event.

 

Retrying that again, I see I had simply put my delay on the wrong loop.  It does in fact appear to dequeue upon the completion of the event case. Thanks!



I saw my father do some work on a car once as a kid and I asked him "How did you know how to do that?" He responded "I didn't, I had to figure it out."
0 Kudos
Message 7 of 9
(4,317 Views)

Although a bit old, somethings may have changed a bit, the best discussion and examples about Events

 

https://libraries.io/github/JackDunaway/LabVIEW-User-Events-Tips-Tricks-and-Sundry

 

mcduff

0 Kudos
Message 8 of 9
(4,280 Views)

@mcduff wrote:

Although a bit old, somethings may have changed a bit, the best discussion and examples about Events

 

https://libraries.io/github/JackDunaway/LabVIEW-User-Events-Tips-Tricks-and-Sundry

 

mcduff


Yeah, NI made some massive updates to event handling the following year (2014).  I think most of his tricks still work, but some got fixed.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 9 of 9
(4,274 Views)