NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How to wait until new thread sequences are completed?

Solved!
Go to solution

Hi,

 

I'm experimenting with executing sequences in parallel. Attached is a screenshot about the main sequence. As you see after an initial popup it calls the cartridge sequence multiple times, each one in a new thread. This subsequence is a dummy, currently it just waits a random amount of seconds and then throws a popup. The point here is to simulate that executing the called subsequences might take different times.

 

Once the for loop is done, my main sequence continues the execution and immediately throws me a popup that the main sequence is completed.

 

The thing is that I'd like the main sequence to wait until all the subsequences are completed. To achieve this I guess I need some sort of a rendezvous, but what would be the implementation? (if can be implemented at all on my sequence, witch has no process model at this time and starts the subsequences in new threads)

 

The sequence file is also attached. I guess I should use the batch model here (or the parallel), but for now I try to keep things easier and not involve a process model, if thats possible.

 

EDIT: Also its important that this main sequence may lauch different sequences in the for loop. Those will be separate sequence files on the hard drive, not subsequences of the file attached.

 

Thanks.

 

1984_0-1784707726729.png1984_0-1784707726729.png

 

0 Kudos
Message 1 of 6
(705 Views)

You mean spawning multiple sequences in their own thread and wait at the end of the MainSequence? Or after the ForLoop?

0 Kudos
Message 2 of 6
(683 Views)

@Oli_Wachno wrote:

You mean spawning multiple sequences in their own thread and wait at the end of the MainSequence? Or after the ForLoop?


After the for loop. I want the popup in the cleanup to execute only when all the sequence calls in the for loop are completed. And again, at the end the for loop might call different sequence files not just calling the same subsequence.

0 Kudos
Message 3 of 6
(673 Views)
Solution
Accepted by topic author 1984

You can store a reference to each thread you start in a local variable and create a synchronization point somewhere later in the code with a wait step pointing to this reference. The example is a simple and stupid implementation.

 

Oli_Wachno_0-1784727944869.pngOli_Wachno_0-1784727944869.png

 

 

 

 

Message 4 of 6
(656 Views)

@Oli_Wachno wrote:

You can store a reference to each thread you start in a local variable and create a synchronization point somewhere later in the code with a wait step pointing to this reference. The example is a simple and stupid implementation.


Thanks man, this works. I'm amazed how teststand is capable to hide information from the user. I scratched my head a lot on how the MyThreadRefs array is populated, and it took me a while to figure that in the sequence call step I have to click to the little wrench icon.

 

(Another solution cound be is to pass the NumberOfLoops variable (by reference) to the subsequences and let them decrement it by one at their last step in the cleanup part. Then we can wait until the NumberOfLoops variable is zero.)

0 Kudos
Message 5 of 6
(626 Views)

Feel free to mark this thread as solved, if yout questions are answered.

0 Kudos
Message 6 of 6
(591 Views)