LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why when are several "While loops" working in parallel the last that has been created sometimes does not work?

Why when are several "While loops" working in parallel the last that has been created sometimes does not work?

In order to solve this, I add another empty "While loop" that does do nothing, being this last the loop that does not work. Therefore it does not affect the rest of the program, working everything correctly.
I think that this is not the form to solve the problem.

Greetings
0 Kudos
Message 1 of 6
(3,079 Views)
You're going to have to be a bit more specific about "does not work". How does it not work? Can you post some example code that demonstrates the problem you're seeing?
Message 2 of 6
(3,065 Views)
You will have to be more specific if you want more specific help.

One problem could be starvation - If you want to run several while loops in parallel, they have to be cooperative.

This means that every loop has to either:
1... Have a WAIT function (Wait X mSec or Wait until next mSec multiple).
2... Have an EVENT structure.
3... Have an operation that causes a sleep, such as TCP WAIT ON LISTENER, or READ ANALOG INPUTS with a reasonable (nonzero) timeout value.

(There are probably other cases I am forgetting at the moment).

The idea is that if you don't give the CPU time, some things won't get done.
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 3 of 6
(3,044 Views)
HI.

The loop does not work, this means that loop is not executed is to say that never is repeated.

I append an example in which when executing the program sometimes are executed all loops and no other times, normally after pressing "Off",(button of my example).
This is the problem.

Thanks to all.
0 Kudos
Message 4 of 6
(3,022 Views)
I just ran your vi, set Sampling to 100, Duration to 1, and then clicked the ON button. All loops worked, front panel indicators all were changing, and when the time counted down to 0, the processing stopped. I ran it again, this time pressing the OFF button as it was processing and it stopped. It seems to be working here just like it was coded. I ran it several times and the last loop worked every time. The only thing I could see is if Sampling was too small, the CPU time might be overloaded and some loops would not get execution time.
- tbob

Inventor of the WORM Global
0 Kudos
Message 5 of 6
(3,014 Views)
After you have pressed STOP the value of the indicator OFF is TRUE and all loops are halted; the next time you press ON its value is still TRUE and if a while loop starts before the TIME CONTROL loop it will be halted at its first iteration.
To solve it you have to reset the OFF indicator (FALSE) before starting the while loops: place a local variable outside the loops and wire a FALSE constant, use a sequence struct. to make sure the indicator is OFF before the loops are executed.
Message 6 of 6
(3,009 Views)