NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How to Stop Thread Within TestStand

Solved!
Go to solution

I am a relative "newbie" to TestStand in this aspect.  I am creating an sequence to generate CAN Bus Traffic in hopes of getting to a more accurate throughput measurement.  The Subsequence I am creating is a designed infinite loop and I am specifying that the loop be run in a separate thread from the Execution Options setting.

 

My question is how I then kill this thread in the cleanup of my sequence.  Since I plan to run the sequence multiple times would not want to have multiple threads running unchecked on my machine.

 

I can't see an easy way to do this.  I imagine something like this has been accomplished before.

 

Any suggestions?

0 Kudos
Message 1 of 6
(10,007 Views)
Solution
Accepted by topic author mvterry

The best way to do this to have your main thread tell the other thread when it is time to exit and then after the main thread has done this it should then wait for the other thread to exit (the waiting will happen automatically if you had the "Automatically wait at end of sequence" checkbox checked on your asynchronous sequence call step).

 

One of the easiest ways to do this is to pass a boolean parameter by reference into your asynchronous subsequence and have your subsequence check that boolean periodically to see if it should exit. The main sequence can then set this boolean in its cleanup steps.

 

Another way is to use a Synchronization step type such as a notification step type and have your asychronous sequence check for a notification that your main sequence will set in its cleanup.

 

It's important that your main sequence wait for the other thread to exit before completing so either use the "Automatically wait at end of sequence" sequence call option or add an explicit wait step to your cleanup of your main sequence after you have notified the other thread to exit.

 

Hope this helps,

-Doug

Message 2 of 6
(9,997 Views)

Doug

Thanks for the suggestion.  Any example of how this is done? Notification step is very new to me.  Can't find Checkbox in my version of TestStand (4.2.1)

0 Kudos
Message 3 of 6
(9,987 Views)

The checkbox for "automatically wait for thread at end of sequence" is on the advanced panel (a button brings this up) of the sequence call when you have new thread selected.

 

I don't think there is an example of this exact use case, but if you try inserting a Notification step into a sequence and take a look at the online help for it, hopefully it will be pretty easy to figure out.

 

-Doug

0 Kudos
Message 4 of 6
(9,982 Views)

Doug,

 

I was just about to write back and say I found the checkbox.  I think I have a grasp of what you were saying about the notification or even using the Boolean variable.  If I set the boolean to false in the MainSequence cleanup tab.  In the thread I can have the infinite loop break upon boolean != TRUE.  The sequence would then end and the thread close.

 

I think this will work.  Thanks for setting me on the right path.  I become an expert at this yet.Smiley Wink

 

0 Kudos
Message 5 of 6
(9,979 Views)
Worked like a charm.  Thanks again.
0 Kudos
Message 6 of 6
(9,975 Views)