NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Thread synchronization

Hi
 
I have the following scenario
 
1. SubSequence A in a sequnce file launches subsequence B in a separate thread
2. Subsequence B has
   -  while (CancelThreadRequest == false)
            wait for .1 s
            if condition true
                  Launch a message box B
3. After initating Subsequence B in separate thread it performs lots of dll and other subsequence call. At a certain point in its flow, it launches a message box A.
 
 
The following is what I want
 If message box A is waiting for user input, message box B can be launched, but if message box B is waiting for user input, launching of message box A must wait till the user is done with box B.
 
I am aware with the concept of semaphore but I don't think that works here. There seems to be a lot of thread synchronization controls in test stand, but I am not sure which one of them wll be best to use in this case.
 
I will appreciate your input in this regard
 
 
Ifti
0 Kudos
Message 1 of 7
(4,312 Views)
How about:
 
 
Lock "MessageBoxLock"
Release Lock "MessageBoxLock"
Display MessageBox A
 
and
 
Lock "MessageBoxLock"
Display MessageBox B
Release Lock "MessageBoxLock"
 
 
B will hold the lock while it is up, preventing A from getting past the lock. A acquires and immediately releases the lock, so it doesn't block B.
0 Kudos
Message 2 of 7
(4,309 Views)

Thanks. I am not exactly sure when threads can switch in TestStand, so if the following occurs sequentially in time

Lock "MessageBoxLock"
Release Lock "MessageBoxLock"
Thread is switched  to B(I am not sure whether TestStand can stop this from occuring)
Lock "MessageBoxLock"
Display MessageBox B
Thread is switched  to A
Display MessageBox A
Thread is switched to B(I am not sure whether TestStand stops this from occuring)
Release Lock "MessageBoxLock"
 
 
 
then my requirements are not met. But if we can be sure that no thread switching takes place between the block of code protected by Lock and release than it is fine.
 
Let me know.
 
Ifti
0 Kudos
Message 3 of 7
(4,289 Views)

If you are just trying to prevent an common user interface annoyance, that scenario is probably not worth worrying about.

It is hard to making it 100% fool proof without writing your own message box, because you need to release the lock after A displays, but before it returns from waiting for user input.

0 Kudos
Message 4 of 7
(4,286 Views)
I think if I make the popup B to be the active window as long as it exists, shall be good for me. I  can easily do it in .NET. I was wondering if I can make the TestStand message box to remain active as long as the user povides an input? Secondly, I was just curious if TestStand provides a way to make part of a seqeuce to be nonpreemptive?
 
Ifti
 
 
0 Kudos
Message 5 of 7
(4,281 Views)
I tried the Modal option on the MessagePopup, but it doesn't prevent another non modal popup from coming to the front from a different thread. I'm not sure whether the modality of a .net popup would be thread specific.
 
To prevent another thread from pre-empting a thread, you can try the Synchronization>>Advanced>>Thread Priority step.
 
This step just sets the windows SDK thread priority. Before using this step it would be best to refer to the msdn documentation (http://msdn2.microsoft.com/en-us/library/ms686277.aspx) to get information on the various issues and caveats involved in altering thread priorities.
0 Kudos
Message 6 of 7
(4,278 Views)
Thanks.
0 Kudos
Message 7 of 7
(4,277 Views)