07-02-2009 02:38 PM
I have a program that has 2 while loops running at the same time. For each, I have a dedicated Boolean variable that when TRUE, will exit the While Loop.
So I can click on one of the controls, that stops one loop, click on the 2nd control, the 2nd loop stops, & that causes the program to stop.
What I would like to do is to have the program stop whenever any one of the 2 controls is clicked.
I've tried ORing the control of one & the local variable control of the other into the While Loop Stop condition, but I've noticed that the local variable doesn't update the value of the variable that sits in the other loop... Is there a better way to make a variable's new value available in both loops simultaneously ?
ak
07-02-2009 02:42 PM
What do you mean by "simultaneously"? Changing a control will all change the value that is in the local variable of that control. But the local variable may or may not be read at the instant you want it to. This is the essence of a race condition.
Why don't you post a simplified example of your code so we can see what you are trying to do?
07-02-2009 02:55 PM
07-02-2009 03:07 PM
Hi Brian,
The functional global variable sounds interesting...but I have LabView 8.0. Would you be able to convert your example to 8.0 so I can see what you mean ?
ak
07-02-2009 03:38 PM
07-02-2009 03:53 PM
ak,
can you post your original vi. It sounds like what you described works. I coded up what I thought you were trying to say and it works fine. It can also be accomplished with a single boolean rather than two.
07-02-2009 04:47 PM
Tim,
Your program also works for me. But mine involves a Event Structure - see the attached picture of the Block Diagram.
ak
07-02-2009 04:49 PM
Brian,
Thanks - when I opened it up I got an error :
Looks like I can get the program to stop by using the Application Control > Stop inside each of the 2 loops...
But it doesn't really teach me how to deal with variable value sharing when running multiple processes.
ak
07-02-2009 07:30 PM
The picture of your error message doesn't show because your picture file is located on your hard drive. We can't access that from the web. Don't use firefox's screenshot feature. Attach your image file to your message.
Why didn't you actually attach your VI like I asked?
In general, multiple event structures can cause problems. However, without seeing your actual VI, I can't tell if you'd have a problem or not. If your code is structured just right, you can put an event case in each event structure that will handle the value change for both buttons. So in loop 1, the event case is for value change of Stop1 and also value change for Stop2. Same thing in Loop2
However, having two stop buttons where either one could stop the code is not very intuitive for the user. There are many examples throughout the forum showing better ways to stop multiple loops, even ones that use local variables. Also using queues to pass commands from a producer loop containing a single event structure to a consumer loop that would not have an event structure.