02-05-2013 12:01 PM
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 🙂
Solved! Go to Solution.
02-05-2013 12:40 PM
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.
02-06-2013 01:12 PM
Thank you, this completely solved my problem!