LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Semaphore

Hi
I know what are semaphores.But  I want to know how to use Semaphore. Please send an example with proper documentation.I am not able to understand the in build example.
Please help it is very urgent.
 
Raman
0 Kudos
Message 1 of 3
(2,707 Views)
Hi Raman,
I don't have a simple example at hand, but I can explain a little bit the behavior of the example vi Semaphore with subVIs (I guess it's the same you have).
In this example, a semaphore is used as a mutex, i.e. it regulates access to a single resource in such a way that only one running vi can get this resource.
The shared resource in this case is the Data Device vi, that simulates an instrument/input channel.
The main vi create the semaphore with size 1. The three subvis try simultaneously to access the Data Device by Acquiring the semaphore, but only one of them will get it.
After the data have been acquired, the vi Releases the semaphore, thus another vi can get the resource.
At the very end, the semaphore is destroyed before closing the main vi.
Of course, if you create a sem with size 2, two vis could Acquire it at the same time, and the semaphore is no longer a mutex
Hope this helps.

Paolo
Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 2 of 3
(2,696 Views)

Hi Raman

I'm using semaphores for the following reason,

I have four units I need to test in parallel mode, during the tests I access a Imaq Card (which is one resource) to aqcuire an image from each unit to proccess it, since I have different units they all need to access the same resource at any given time, there is where the semaphores come into action,

my low level driver is going to manage the semaphore and I just call my tests using what is call threads which in LabVIEW is not really that difficult when you change a property on the vi to make the file reentrant, once you access the resource at different times, the semaphore will allow only one unit under test to access the resource,

I hope this helps

0 Kudos
Message 3 of 3
(2,685 Views)