From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, 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: 

Can't terminate while loop in producer/consumer

Solved!
Go to solution

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.

0 Kudos
Message 1 of 3
(2,707 Views)
Solution
Accepted by topic author VI_Joe

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.

Message Edited by Ravens Fan on 08-10-2009 10:09 PM
Message 2 of 3
(2,693 Views)

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....)

 

Message Edited by altenbach on 08-10-2009 11:33 PM
Download All
Message 3 of 3
(2,670 Views)