From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Semaphore timing

Solved!
Go to solution

Hi! I have a question on the order in which semaphores are acquired and released. I've looked a the semaphore example and from what I can gather the order in which the semaphores are requested is respected. 

 

I have two processes and they must execute one after another. These processes are in seperate VIs and take an indeterminate amount of time to execute. I have one semaphore that is grabbed by one process, released, grabbed by the other process, released, and so forth. 

 

My question is this. How can I be sure that right after one process releases a semaphore, the other one grabs it? Isn't there a chance that the very process that just released the semaphore can re-aquire the semaphore before the other process had a chance to request it? 

 

Am I banking on the fact that the time it takes to loop back to the request, after the release, will always be less than the time it takes to run the code within my process?

 

Thanks!

PS. i've been trying to find more documentation besides the help file and pre-loaded semaphore example on labview's implementation of semaphores. If anyone has any other docs that would think would help clarify labview semaphore concepts feel free to send them my way 🙂

0 Kudos
Message 1 of 3
(2,445 Views)
Solution
Accepted by topic author PaulSammut

If you want to always have a ping pong setup, where A runs, then B, then A, etc., then I would suggest creating two queues - one for each process. At the start, each process dequeues from its queue using an infinite timeout. Because the queue is empty, it will be forced to wait until there's an element in the queue. When the process is done, it enqueues an element into the other process's queue, which will allow the other one to resume.

 

To initialize the system, you enqueue an element into Queue A.

 

The same concept can be implemented using several other methods, but I think the queue is the easiest.


___________________
Try to take over the world!
Message 2 of 3
(2,435 Views)

Thank you, this completely solved my problem! 

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