11-19-2014 11:55 AM
Let say that I have 3 parallel threads, all state machines.
Thread 1
- loop rate 1ms
Thread 2
- loop rate 50ms
Thread 3
- loop rate 5ms
Supposedly, all of the threads should start at approxiatemly the same time. However, if somehow Thread 2 got the priority over Thread 3, and the program get stuck in Thread 2 for 1s. Thread 3 could start 1s late. Is that correct?
11-19-2014 11:59 AM
Okay need a little context. Is this real-time or non-deterministic OS like Windows? Also is there coupling that prevents loop 3 from running until loop 2 runs?
If you have 3 loops all running in parallel, and there is no resource locking, or waiting for a loop to reply with data, then they all run independent of one another, and even if one loop pauses the other two should continue regardless of priority.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
16 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
11-19-2014 12:09 PM
The loop rate doesn't matter. What matters is whether the amount of work to be done inside the loop takes the entire loop period. If you have a high-priority 1ms loop that doesn't do anything (or does very little) then it will still yield time to other loops. On the other hand, if your 1ms loop actually has 5ms worth of work inside it, then that loop may never yield time to any other loop. (In theory, at least - but any value of wait, even 0ms, as an input to the Wait (ms) function will cause the loop to yield to other tasks, at least momentarily.)
Some other factors that influence the interaction between loops include whether you're using timed loops or normal while loops, how many processor cores you have, and whether the loops are in the same or different execution systems, since those will affect whether they're all in the same thread or different threads.
11-19-2014 12:31 PM
As the others have said, there are way too many variables to really answer your question. What OS (RT vs Windows)? What are the loops doing? How are their rates set? How did you set priority? What hardware are you using (CPU mostly of concern here)?
11-19-2014 02:27 PM
window xp in a pxi controller.
11-19-2014 02:28 PM
window xp in a pxi controller. no coupling.
11-19-2014 02:30 PM
normal while loop, same execution system, dual core
11-19-2014 02:48 PM
No one is going to be able to give you a completely satisfactory answer, because you really don't know - especially on Windows, where the operating system could interrupt or delay processing unexpectedly. The actual code will make a difference, whereas the loop rate, as I explained before, will not. What is your actual concern? Do you need the three loops to start precisely synchronized?
11-19-2014 02:56 PM
The loop doesn't have to be syn, but they all need to start ASAP. i see that one loop is delayed by 1s.
11-19-2014 02:58 PM
What is happening in that one loop? Can you share any code that would give us a better idea of what your program is doing?