LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Race Conditions - If there is only one writer to a local variable, can you get incoherent data?

I have two independent loops. One loop writes to a local variable, while the other loop reads the same variable. The loops are completely independent and running at asynchronous and non-deterministic rates. Am I running the risk of getting 'bad' data? IE - will LabVIEW actually allow the variable to be read while it is being changed in the OS at the lowest level, and thus it is possible in my reading loop to get a value that is completely bogus? All I want to accomplish is to have access to the most recently written value. Using queues or semaphores seems like alot of overhead for such a simple and common task.
0 Kudos
Message 1 of 6
(3,859 Views)
You won't get any bogus data. All data will be valid and represent the current state of the local variable.
0 Kudos
Message 2 of 6
(3,859 Views)
This will work fine, no risk.
0 Kudos
Message 3 of 6
(3,859 Views)
> Am I running the risk of getting 'bad' data? IE - will LabVIEW
> actually allow the variable to be read while it is being changed in
> the OS at the lowest level, and thus it is possible in my reading loop
> to get a value that is completely bogus? All I want to accomplish is
> to have access to the most recently written value. Using queues or
> semaphores seems like alot of overhead for such a simple and common
> task.

LV automatically protects the various accesses of terminals, locals,
globals, and functions calls. There really isn't a way to get mixed
data except by using something like peek and poke or DLL calls to look
at data being written by something else.

Greg McKaskle
Message 4 of 6
(3,859 Views)
Thanks for the re-assurance. So it appears knowledge base article #28Q6L7B5 is incorrect? That is what got me thinking (and scared) about all this.
0 Kudos
Message 5 of 6
(3,859 Views)
The article is OK, it does not state that values can be corrupted.

The loosing of data the article refers to just means that you are not sure the reader will see *all* the values that are written to the local (due to the fact that the local may be written to multiple times between reads) and it may not see it at the correct time (reads may occur at varying time offsets from the writes).
0 Kudos
Message 6 of 6
(3,859 Views)