NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How to wait for all threads created in a loop?

Solved!
Go to solution

Hi, 

 

I am somewhat new to teststand. I have a situation that I can't find much information on. I suspect there is some simple solution like an unchecked box somewhere.

 

I have a For Loop that starts a varying number of asynchronous measurements on separate cDAQs in new threads. (it can be 1, 2, or 3 for now but could be expanded in the future) Each measurement is the same sample rate and number of samples, but there is some variance in the time it takes to send the command and return data from each cDAQ. I want to wait for all the measurements to complete before continuing and making calculations on the data. It seems that my 'Wait for Thread' is only waiting for the first thread to finish and not all of them. 

 

Is there a way to wait for all (1-3 threads) of them? For now my best solution is to change the "Wait for Thread" to just be the expected measurement time plus a little bit of "cushion". 

 

Sequence.PNG

 

WaitSettings.PNG

 

 

 

0 Kudos
Message 1 of 5
(2,222 Views)
Solution
Accepted by topic author db28

There are probably some other ways to do this, but an easy way that comes to mind is to drop your for loop in a subsequence.

 

When you call a sequence in a new thread, this advanced setting is on by default:

Capture.PNG

If you call all of your async sequences from a synchronous sequence, it won't return to the parent until all of the async ones finish.

 

Hope this helps!

Trent

https://www.linkedin.com/in/trentweaver
Message 2 of 5
(2,183 Views)

Thanks for the response. The subsequence worked for me, but I actually ended up using the "Store an Object Reference to the New Thread" option a few lines below what you underlined in the advanced settings.

 

That was what I was hoping was available but I didn't know where to look or how to phrase it. 

0 Kudos
Message 3 of 5
(2,120 Views)

Hey I was looking for adding wait step such a way that it waits until my "value" stabilizes. There is no fixed time that will vary from value to values. Any suggestion on how to use wait step in that case?

0 Kudos
Message 4 of 5
(1,216 Views)

@Ashuk

This question should probably be posted as a new topic.

 

But...

I don't think a 'wait' step will help you unless you already have a subsequence to determine when the value is 'stable'.

 

I would create a loop to check the change in value between consecutive measurements and then exit the loop if the change is less than whatever a "stable" amount would be. Maybe check that it is in range for multiple loops. 

 

 

0 Kudos
Message 5 of 5
(1,204 Views)