

One disadvantage of functional global variables is that when you want to change the way you modify the resource they hold, you must change the functional global VI block diagram and add a new action. You can solve most synchronization problems with functional global variables, because the functional global VI ensures that only one caller at a time changes the data it contains. You also can use functional global variables to protect access to global resources, such as files, instruments, and data acquisition devices, that you cannot represent with a global variable, since calls to the functional global variable execute sequentially unless you mark the VI as reentrant. Depending on the action parameter, the case inside the loop initializes, does not change, incrementally increases, or incrementally decreases the value of the shift register.Īlthough you can use functional global variables to implement simple global variables, as shown in the previous example, they are especially useful when implementing more complex data structures, such as a stack or a queue buffer. The actions in this example are initialize, read, increment, and decrement.Įvery time you call the VI, the block diagram in the loop runs exactly once. The following illustration shows a functional global variable that implements a simple count global variable. The VI uses an uninitialized shift register in a While Loop to hold the result of the operation. A functional global variable usually has an action input parameter that specifies which task the VI performs. Functional global variables are VIs that use loops with uninitialized shift registers to hold global data.

From the LV help page titled "Suggestions for Using Execution Systems and Prioritites":Īnother way to avoid race conditions associated with global variables is to use functional global variables.
