Race conditions can occur when two pieces of parallel code modify the same variable. For example, two sections of code write a variable's value at the same time. The section of code that saves the variable's new value last overwrites the other code's written value. This can result in unexpected values when reading the variable later down the line.
Functional Global Variables can be used to prevent such actions that modify data. Please note that all critical sections of code must be protected by a non-reentrant FGV as a whole; this ensures that only one action executes at a time, so conflicting operations can never perform in parallel. Refer to Reentrancy: Allowing Simultaneous Calls to the Same SubVI
for further information.
As a bad
example, the following two parallel operations provoke a race condition, as the critical read-modify-write operations are implemented outside of the FGV:
In contract, in the following good
example the critical read-modify-write sections of code have been implemented as actions of the FGV. As the FGV's non-reentrancy setting ensure only one action executes at a time, the two calls will always execute after each other, preventing a race condition.