04-27-2010 04:37 AM
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!
Solved! Go to Solution.
04-27-2010 08:55 AM
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
04-27-2010 10:02 AM
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
04-28-2010 03:20 AM
04-28-2010 07:19 AM
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
04-29-2010 03:58 AM
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!
04-29-2010 10:29 AM
Julyfly,
The LockDemo.seq example that I referenced in my first post should help for what you want to do.
-Jack
04-29-2010 11:44 AM
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
02-02-2015 10:29 PM
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.
02-03-2015 08:32 AM - edited 02-03-2015 08:38 AM
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