LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

thread priority

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?

 

 

 

 

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 1 of 17
(3,053 Views)

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.

Message 2 of 17
(3,049 Views)

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.

Message 3 of 17
(3,041 Views)

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


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 4 of 17
(3,032 Views)

window xp in a pxi controller.

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 5 of 17
(3,016 Views)

window xp in a pxi controller.  no coupling.

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 6 of 17
(3,015 Views)

normal while loop, same execution system, dual core

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 7 of 17
(3,013 Views)

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?

Message 8 of 17
(3,004 Views)

The loop doesn't have to be syn, but they all need to start ASAP.  i see that one loop is delayed by 1s.  

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 9 of 17
(2,997 Views)

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?


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 10 of 17
(2,993 Views)