NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How to programmatically obtain locks?

Hello all,
             Is there any API call available in TestStand 4.0 that helps me to know whether a step is being accessed by multiple threads at a time. And if that case occurs... Is there any mechanism to obtain locks to that step programmatically?

Any help is greatly appreciated...

Thanks
Arun Prasath E G
0 Kudos
Message 1 of 11
(2,574 Views)
I'm not sure how to tell if it's being accessed by multiple threads but you can set the "Use Lock to Allow Only One Thread at a Time to Execute the Step" property.  This is in the step's Properties under Synchronization.  If you check that checkbox then it automatically creates a lock for that step so only one thread can execute it at a time.  You can read more about this in the TS Help as well.   
 
If you have a series of steps that you want to lock then use the Lock step.  There are examples in your example folder.  There is a LockDemo as well: C:\Program Files\National Instruments\TestStand 4.0\Examples\Synchronization
 
The thing I'm hung on is your wording.  When you say access do you mean that multiple threads will execute the step?  or just get some of it's subproperties?
 
Hope this helps,
jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 2 of 11
(2,558 Views)
Steps have a lock synchronization setting on them, and there is also a separate lock synchronization step type you can use. These things can also be accessed programmatically, but that's not normally necessary. If you provide more details about what you are trying to do I can suggest a solution.

-Doug
0 Kudos
Message 3 of 11
(2,556 Views)

HI All,

Thanks for your comments...

But my requirement is, I want to know whether a step is executed by multiple threads dynamically. I believe the lock methodology pointed out by you is static in nature. However I need to determine the step nature(multiple thread executing a single thread at a time) dynamically at run-time and once this scenario occurs.. I need to obtain the lock dynamically to that step. So in this case, even when multiple threads trying to exectue a step.. my module will create a lock dynamically on that step and that in turn allows the step to permit only one thread to execute at any point of time...

waiting for your reply,

Thanks

ArunPrasath E G

 

0 Kudos
Message 4 of 11
(2,526 Views)
Hey Arun,
 
I'm not sure I understand what you are talking about.  Why would you need ot create the lock dynamically?  The cases that Doug and I pointed out are the best way to create locks that ensure only 1 thread will be executing that step at a time.  It's easy to implement and the TestStand engine takes care of everything for you. 
 
Here is what I understand from your explanation:
 
1- you have a sequence with a step that cannot be executed simulatenously by different threads
2- you have some sort of asynchronous thread monitoring that step to determine if multiple threads will be accessing it
3- once you detect more than one thread accessing that step at the same time you will dynamically turn on it's locking
4- once thread A is finished with the step then thread B will have a shot at it
 
Please let me know if I understand you correctly.  If I don't then please be detailed in exactly what you mean.  If I am correct then the best thing is to do what Doug and I pointed out.  As I said before.  The Engine does all the work for you.
 
Regards,
jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 5 of 11
(2,504 Views)
I thought of something else,  Are you dynamically creating your sequences and steps?  And that's why you need to know how to turn on the locking dynamically?
jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 6 of 11
(2,502 Views)
Prasath,

What you are saying is not how thread synchronization typically works. Typically when synchronizing threads you don't dynamically detect that multiple threads are inside of a function and then, after the fact, lock. What you do instead is acquire a lock before the critical section of the code that you want to protect, and release the lock when that code is done executing. There is no need to detect whether or not multiple threads are actually calling into the function inorder to get the lock or not as getting the lock is harmless even if there is only one thread. Further more, in order to implement what you are saying (detecting when multiple threads have called into a function and locking) would require a lock anyway to synchonize the detection of multiple threads so wouldn't really be saving you any time or resources.

Basically all you really need to do is use the step's lock setting (on the synchronization settings page) for your steps.

Hope this helps,
-Doug
0 Kudos
Message 7 of 11
(2,496 Views)

Thanks All for your comments

Thanks

ArunPrasath E G

 

0 Kudos
Message 8 of 11
(2,477 Views)

Hi Doug,

I've an application with steps that have a locks set at the Properties>Synchronization>"Use Lock to Allow......".

These steps call the VI "X" and it handles or use some HW resources which are shared among the threads (Test Sockets of a Parallel Model). But now I have to expand the functionallity and sometimes the VI "X" will be called into anothers VIs but not from another steps anymore.

Possible solution would be to get the Lock name or object programatically and somehow get into this lock queue (or whatever way it works) or at least call it progamatically to get a chance to use the VI "X" as well the HW resource associated to it.

 

Definitally the VI is set to non-reentrant which seems to be a lock to the VI but I wonder of Test Stand and LabView are able to handle that simple because reentrance is not hold by a explicity lock but probable a implicity one.

 

Seems that you know how to call it programatically by your comment.

I've been digging into APIs but still not find that. Might you kindly share you finds  about it if you got my ideia.

 

Best regards

 

Arminio

 

0 Kudos
Message 9 of 11
(1,830 Views)

It is possible to access and use TestStand locks programmatically, however if all of your code is written in LabVIEW, you might want to use a labview Semaphore internally in the VIs instead (see LabVIEW help for details).

 

To access a TestStand lock in labview you will need a reference to the SyncManager which you can get from the TestStand engine API Engine.GetSyncManager. You can then use that reference with invoke and poperty nodes for the TestStand Synchronization Manager COM server. The Mutex object type is the one that corresponds to a TestStand lock. See the TestStand help file for more details.

 

Hope this helps,

-Doug

Message 10 of 11
(1,821 Views)