LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Semaphores and SubVIs

Okay gang, I'm trying to break my program down into 4 subVIs and running into a snag. In my main vi I create a semaphore, which is passed to a subVI where within this subVI the semaphore is both created and released.
 
It is not working properly. I read that you cannot used a created semaphore in more than one instance, so does that mean if I create the semaphore in my main VI, I can't lock and unlock it in the subVI code?
 
Thanks!
 
-- Jason Pugh
0 Kudos
Message 1 of 7
(3,916 Views)
I mistakenly said that I "create a semaphore" in my subVI. What I meant was that in this subvi I acquire and release the semaphore that was created in the main vi. Sorry for the confusion!
 
-- Jason
0 Kudos
Message 2 of 7
(3,908 Views)
There is no such restriction. Take a look at the example that ships with LabVIEW. It's called "Semaphore with SubVIs". From the NI Example Finder do a search for "semaphore".
Message 3 of 7
(3,906 Views)
Thanks! I was looking at those examples earlier but didn't see that they also acquired and released within the subVI. One last question if you don't mind...

How do you create a semaphore reference? I don't have a semaphore refnum under #refnum and I tried just copying the one from the semaphore example to the front panel of my subVIs but apparently there is something more you must do, as it actually wasn't working like it did before moving the code to the subVI. Thanks!


-- Jason
0 Kudos
Message 4 of 7
(3,903 Views)
And for the sake of full disclosure, I have a semaphore getting created on the main page. Also on the main page, I have an acquire semaphore that attempts to grab it. The other acquire is within a subvi. I don't know if that makes a difference, whether or not all acquire semphores are within subvis or not. In the end, they all will be but I'm making sure it works before I go through the effort of moving the code to subVIs. Thanks!

-- Jason
0 Kudos
Message 5 of 7
(3,896 Views)
I assume you're referring to creating a semaphore control/indicator. The easiest way of creating a semaphore control is from the semaphore functions. Right-click on the "Acquire Semaphore" subVI's "semaphore" input and select "Create -> Control".

You can have the "main" VI try to acquire the semaphore as well as the subVIs. If you start with the example I mentioned previously, you can take the code of one of the subVI and place it right in the main VI. Then, just connect the semaphore wire to the loop's tunnel and run the main VI. Now there will be a fourth graph on the main VI that gets updated along with the three subVIs.
Message 6 of 7
(3,895 Views)
Thank you Smercurio_fc! Turns out I WAS doing the semaphore stuff right, I just somehow managed to switch some wires up when I was moving stuff to the subVIs and the conditional check when to acquire the semaphore wasn't right so it never was locking it out. Stupid mistake, but at least it does indeed work. I was afraid that I had been programmatically backed into a corner. Thanks again!
 
-- Jason
0 Kudos
Message 7 of 7
(3,869 Views)