Race Conditions

Because VIs follow a dataflow execution model, LabVIEW local and global variables do not behave like local and global variables in text-based programming languages. A race condition occurs when two or more pieces of code that execute in parallel change the value of the same shared resource, typically a local or global variable. The following block diagram shows an example of a race condition.

The output of this VI depends on the order in which the operations run. Because there is no data dependency between the two operations, there is no way to determine which runs first. To avoid race conditions, do not write to the same variable you read from.

If you use global variables in VIs that execute in parallel, you can use an additional Boolean global variable to indicate when global variable data changes. Other VIs can monitor this Boolean global variable to determine if the data changed and to read the new value.

Refer to the Using LabVIEW to Create Multithreaded VIs for Maximum Performance and Reliability Application Note for more information about preventing race conditions.