NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How to set the Lock in parallel sequeces?

Solved!
Go to solution

Hi  all,

i write a testseq , which has two parallel sequences. In both sequences(threads)  a same LabVIEW Programm (Vi) as Action step will be called. Since the Vi use a IP Address, so it cannot be executed more than once at a time. so i want to make a setting like(Lock) in Teststand.

 

 is it possible to use the lock setting(How) to enable  the Vi  as step , which executes once  at a time.

 

Any answer will be appreciated!

 

 

 

 

 

0 Kudos
Message 1 of 13
(5,407 Views)

Julyfly,

 

Have you looked at the LockDemo.seq in the Examples\Synchronization folder? This shows how a batch process works, but the batch sockets run in parallel.

 

The other place to look is the TestStand help for setting individual step synchronization options: Step Properties Dialog - Synchronization

 

Hope this helps.

 

-Jack

0 Kudos
Message 2 of 13
(5,393 Views)
Solution
Accepted by topic author julyfly

The easiest way, if you want to lock on a per step basis, is to use the Lock settings on the step. Look at the Synchronization section of the step settings on the step settings panel. You can use the same lock name with multiple steps to have them use the same lock. If you want to lock around more than one step, then use the Lock synchronization step type.

 

Hope this helps,

-Doug

0 Kudos
Message 3 of 13
(5,388 Views)
hi, thanks  Capt. Jack and dug9000!  i looked the example and thought about, if the same Vi are called in both parallel sequence, that means in both parallel sequence , there are one
action step which will call the same Vis. if i set the same locksname to the two steps, i wonder if it works, that the vis will be called once at a time. since i can't test it
in Hardware Loop until next week, i would like to hear your advices! 
0 Kudos
Message 4 of 13
(5,361 Views)

Yes that is what will happen. The lock name will cause the first to get there to execute, and the block the other(s), once the first step completes, the next step will unblock. If you're only talking about one step, then Doug's advice would be the easier method to implement.

 

-Jack

0 Kudos
Message 5 of 13
(5,352 Views)

hi,  thank you all for the advices!  It works in my programm with only one Step!

Now i try to write a little  complexer programm, there are two or more Vis in Parrallel Seq , which needed to be locked! i used the Batch Sychronistion( Series (one thread a time) of step setting to each step, which need  be locked.  but it failed!  

 

Could you please give me some advices about this Case!

 

Thanks a lot! 

0 Kudos
Message 6 of 13
(5,326 Views)

Julyfly,

 

The LockDemo.seq example that I referenced in my first post should help for what you want to do.

 

-Jack

0 Kudos
Message 7 of 13
(5,307 Views)

Batch synchronization is for the batch model only. Just use the Lock step type instead. It has a Lock operation and an EarlyUnlock operation. Just put a Lock step with the lock operation at the beginning and the EarlyUnlock operation at the end of the block of steps you wish to lock around.

 

Hope this helps,

-Doug

0 Kudos
Message 8 of 13
(5,301 Views)

Am I missing something in regards to locks and threaded code?  I've tried locking with a string for the name as well as using the object reference and I've tried using an object reference for the Lock Operation lifetime and the code doesn't really behave like I'd expect.  That is...I'd like to be able to apply a lock with one sequence call using the object to control the lifetime.  Then, in a different sequence call complete the operation I started and Early Unlock.  I'd expect any other threads or executions that called the first sequence and wanted to apply the Lock would wait.  But that doesn't appear to be happening.

 

I uploaded the .seq's I created for testing this.  I can't explain what I am seeing other than a Lock step hits and it doesn't seem like using an object reference for lock operation seems to matter. 

Download All
Message 9 of 13
(4,528 Views)

Your example sequences aren't doing what you say you're wanting to do, and have some issues with them.

 

1) You are creating the lock in a new thread, but since that is happening asynchronously there is no guarantee it will do so before any other steps in your other threads run. I'm not sure why you are creating it in a new thread at all though. You could just create it in the main thread.

 

2) Your second thread is looping on a sequence call which is Locking and Unlocking the lock in a tight loop. It has an early unlock step in it, but it isn't unlocking a lock from a parent sequence, it is unlocking the Lock acquired in the same sequence 3 steps above it.

 

3) Your third thread is calling a different sequence in a tight loop which is repeatedly locking the lock, and effectively unlocking its previous lock of the lock because it's storing the lock operation lifetime on the same variable each time. This thread is actually the one which is maintaining ownership of the lock though since you can lock a lock multiple times within the same thread and it's only unlocking the previous reference after having gained a separate lock operation reference when it then tries to store that reference in the same variable as the previous one.

 

It looks to me like the sequences are working as expected, but are perhaps not written the way you intended. If you describe in more detail what you are trying to do, I might be able to suggest a solution.

 

Hope this helps,

-Doug

0 Kudos
Message 10 of 13
(4,517 Views)