08-10-2009 07:39 PM
I have attached a simple vi that was constructed from the producer/consumer (events) template. In the vi I have set up a counter. I want to be able to terminate the counter when the stop button is pressed. This doesn't work as planned. The counter goes to its full count before the program stops. The vi does work as planned when run in highlight execution mode. Can't figure it out.
Thanks in advance.
Solved! Go to Solution.
08-10-2009 09:04 PM - edited 08-10-2009 09:09 PM
Race Condition. Any time something behaves differently with highlight execution than it does at full speed, then suspect it is a timing issue due to a race condition.
As soon as your producer loop has the command queued up, it is ready to handle the next event. If you hit the stop button, it is ready to handle it quickly and the upper while loop ends, and Stop gets reset back to false right away. This probably happens before the consumer loop has a chance to read the local variable of the Stop button in the instant it is true. Have your consumer while loop set the Stop button back to false instead thus guaranteeing the consumer loop has a chance to see it while it is True.
08-11-2009 01:24 AM - edited 08-11-2009 01:33 AM
You can set the stop button to latch action and place it in the lower loop. No local variables needed.
The event will fire right away and the lower loop will reset the button once it's read. No race condition possible. 😉
(Personally, I would probably redesign from scratch....)