11-25-2010 03:15 AM
Dear all!
I'm trying to start the execution of two while loops at the same time using semaphores. I would then like both loops to run synchronously.
I'm using a "wait (ms)" set to 64 ms, one for each loop, so that each iteration of any of the loops last the same time.
I have checked the iteration indicators in both loops after some time of execution. I want these values to be the same but I can't manage to do it.
Could somebody help me? I'm new using semaphores. Should I use notifiers, queues or anything else instead?
I would really appreciate your help. Please, find my code attached.
Thank you very much in advance,
Miren
11-25-2010 03:51 AM
A simple solution is to use Occurance and have one loop generate an Occurance as it ends its loop. The other loop will only need a Wait on Occurance which will limit its loop speed.
/Y
11-25-2010 04:46 AM
Unfortunately, that solution is not enough for me. I would not like the second loop to wait for the occurrence each time the first loop makes an iteration, as in this case, the second loop iteration time would be longer with respect to the iteration time of first loop.
11-25-2010 04:57 AM
@iturriamiren wrote:
Unfortunately, that solution is not enough for me. I would not like the second loop to wait for the occurrence each time the first loop makes an iteration, as in this case, the second loop iteration time would be longer with respect to the iteration time of first loop.
If the loop doesn't wait it'll never be the same amount of loops, unless it's predetermined through a for loop or similar. The Wait command isn't perfect, nor is the OS so the loop times will differ.
/Y
11-29-2010 05:58 AM
Hello iturriamiren,
I’m sorry but semaphores are not the best way to synch actions in two loops. These elements must be used to protect elements from unexpected interactions or protect/arbitrate in the use or shared resources.
If you want your second loop execute code when the first loop does anything, you must use notifications or queues (notifications if second loop is always faster than the first one, or queues for not to lose data):
http://zone.ni.com/reference/en-XX/help/371361G-01/TOC113.htm
http://zone.ni.com/devzone/cda/tut/p/id/3023
http://zone.ni.com/devzone/cda/tut/p/id/5237
Example:
http://decibel.ni.com/content/docs/DOC-9617