LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Flaky operation of event structure with multiple event sources

Solved!
Go to solution

I thought I'd come up with a nice method for inter-process communication, but what I've got is very flaky, making me suspect a race condition.  When you run the VI and repeatedly press the GetMeasurement button, sometimes it works (displays a new value) and sometimes it doesn't.  I put a probe on the UI loop's "UI_Command" data and it doesn't update every time.  So the dynamic event is not always being "received" by the UI loop?  Any ideas out there?  Am I ridiculously abusing events for this purpose? thanks much, paul

0 Kudos
Message 1 of 6
(2,387 Views)
Solution
Accepted by topic author PaulOfElora

You cannot split the Reg Events wire, use one for each loop. See below.

 

Snap18.pngSnap19.png

mcduff

0 Kudos
Message 2 of 6
(2,385 Views)
Solution
Accepted by topic author PaulOfElora

mcduff is absolutely right, I just wanted to add a little bit about what registering for events does. 

 

When you work with queues there is a single queue reference which the sender uses to send data, and the receiver uses to receive data. Multiple senders is fine if you don't care about the order the data is received, so we can use queues with N senders and 1 receiver, also called N:1 messaging. You never want to dequeue elements from a queue in multiple places at the same time, because only one of them can get the element.

 

When you work with events, you get two references. The event reference is used by the sender to send data, and the event registration is used by receiver to receive data. For the same reason you don't want to dequeue from a queue at multiple places, you also don't want to receive events from the same event registration in multiple places. However, if you create multiple event registrations, you will have no problem receiving the event data in multiple places. This could be used for N:N messaging, but usually the event is triggered by a specific module or process in your code, so it tends to be used for 1:N messaging. 

 

If you handle a single event registration in two event structures that have an equal chance at grabbing it, then it will sometimes be handled by both, and sometimes by only 1. If you fire the event N times, it will be handled between N and 2N times total, but not in any repeatable way. In this way, it is a little bit different than dequeueing from a queue in multiple places, because then each element can only be dequeued once.

Message 3 of 6
(2,375 Views)

Thanks for the explanation!

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 6
(2,365 Views)

Ahhh, that makes sense.  Will try & fix tonight.  Thanks to both of you? paul

0 Kudos
Message 5 of 6
(2,352 Views)

Works like a champ with separate refnums - I do appreciate the help, guys!

0 Kudos
Message 6 of 6
(2,350 Views)