LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

synchronization problems with semaphores

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

  

0 Kudos
Message 1 of 5
(2,750 Views)

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

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 2 of 5
(2,744 Views)

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.

0 Kudos
Message 3 of 5
(2,738 Views)

@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

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 5
(2,731 Views)

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

http://decibel.ni.com/content/docs/DOC-2322

http://zone.ni.com/devzone/cda/tut/p/id/5899

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