LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

is it necessary to use semaphores with shared variables

is it ok to use semaphores with shared variables to prevent race conditions or is that built into the shared variable?
- James

Using LV 2012 on Windows 7 64 bit
0 Kudos
Message 1 of 5
(3,166 Views)
I don't have any practical experience with shared variables, but if my understanding is correct, semaphores won't necessarily help you, because they work in a single LabVIEW application instance and shared variables work across instances (and even networks), so there's nothing guaranteeing that someone else won't write to it.

___________________
Try to take over the world!
Message 2 of 5
(3,146 Views)
Semaphores are more of a method to protect a section of code from executing, and as tst as said they won't really help you.  There is nothing inherently harmful about having 2 sections of code trying to write to a shared variable at the same time.  Nothing like a crashed program, scrambled value, or an error message.  What will happen is that whatever happens 2nd is the value that sticks.  So a shared variable can still have the possiblility of race conditions just like local and global variables if you are dealing with multiple writers.  That is really an architecture problem.
Message 3 of 5
(3,142 Views)
Thanks for the input !
 
What if i were using them as single process variables within the same program.  Would semaphores guarantee that a race condition would not occur, or is that unnecessary?
 
 


Message Edited by James R on 04-14-2008 02:16 PM
- James

Using LV 2012 on Windows 7 64 bit
0 Kudos
Message 4 of 5
(3,134 Views)

Try looking at an action engine.

http://forums.ni.com/ni/board/message?board.id=170&message.id=240328&requireLogin=False

I believe it will do what you want.

0 Kudos
Message 5 of 5
(3,125 Views)