LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Darren's Occasional Nugget 08/07/2023

As Steen pointed out, there is a potential race condition in the example. You could avoid that by using data flow dependency. The Register User Events node does have error in an error out terminals for some reason! 😀

 

User Event Test.png

The delay after the Register User Event node is not really needed, it just is there to make it more obvious that the event queue still exists after the events are destroyed.

 


@Darren wrote:

 

It turns out that with events specifically, if you destroy the event reference, an event structure frame for that event will still fire if the event is already in the event queue. This makes events unique among other APIs (queue, notifier, etc.). For example, if you have a queue with elements in it, and you destroy the queue reference, you cannot then dequeue elements that were still in that queue.


I think this remark is a little short in explanation. If you have an unnamed queue, then it is of course destroyed when calling the Release Queue node so there simply is no queue anymore left to deque anything from, no matter how many queue elements were in there the moment you called Release on it. But if you use named Queues and Obtain two Queue refnums to that queue, you can perfectly well release the refnum that was used to enque elements and still deque from the other refnum all the elements in the queue.

 

I'm pretty sure that the Register Events node actually Obtains a refnum to the event for the duration of its call to make sure the event object won't suddenly go away while attaching the event queue to it. Those objects like Queue and Notifier all are internally refcounted objects that allow to obtain a new refnum on it and releasing that refnum won't destroy the object until the last refnum was released.

Rolf Kalbermatter
My Blog
0 Kudos
Message 11 of 16
(914 Views)

@IlluminatedG wrote:

Filter user event? Like having a case structure around the logic that stops something from happening in the event case and "discarding" the intended action?


Discarding Filter Events remove them from the Event Queues with later Event Registration Refnums.  I believe I used a Notifier to set a flag driving Case Structures in each Event Structure that was registered for the same User Event to code a user event pseudo-filter.  😀 not really super elegant but it worked.

 

The direct Event discarding would actually allow the EIW to show the state of the event queues and be "cleaner." 


"Should be" isn't "Is" -Jay
0 Kudos
Message 12 of 16
(874 Views)

I see this a decoupling of the WRITE and READ interfaces for events.

 

It would be really elegant if the data on the READ side didn't expose the WRITE reference.....

 

https://forums.ni.com/t5/LabVIEW-Idea-Exchange/Don-t-expose-the-Refnum-to-a-pre-registered-User-Even...

0 Kudos
Message 13 of 16
(859 Views)

I have wanted User Filter Events a few times.  But every time I feel like I need it, I usually get around it by just reading the event, evaluating if I want to actually take the action, then do nothing with it.  This can usually handle these events quickly enough to make it feel like a filter.  Darren's demo makes sense to me only because I think of User Events as a Publisher Subscriber model, and each unique registration to user events needs to be autonomous.  So destroying the User Event shouldn't stop the queue that was built up.  Still I would have tested this behavior before trusting it.  For shutdown that is great advice to just fire and move on.

0 Kudos
Message 14 of 16
(835 Views)

Here's an updated diagram that doesn't include the race condition, since that was tripping up some people. I also simplified some other stuff too. I'll ask the moderator to update the image in the original post. Thanks for the feedback, everybody.

event2.png

 

0 Kudos
Message 15 of 16
(714 Views)

I feel if they renamed "User Events" to "Event Generators" and "Event Registration Refnums" to "Event Queues", it would a lot easier for people to intuitively grasp.  They are actual very simple and logical, but the naming is awful.

Message 16 of 16
(680 Views)