By default, when LabVIEW calls the same subVI from multiple locations within either the same VI or different VIs, only one instance of that subVI can run at a time. This limitation occurs because the subVI reserves only a single space in memory to store its data, so all instances of the subVI must take turns using that data space. However, if you configure the subVI for reentrant execution, LabVIEW can execute all instances of the subVI simultaneously. In reentrant execution, LabVIEW allocates copies, or clones, of the data space so that separate instances of the subVI have distinct locations to store their data.
|Note (FPGA Module) FPGA VIs are reentrant by default.|
LabVIEW provides the following types of reentrant VIs:
|Usage Considerations||Non-reentrant||Shared Clone Reentrancy||Preallocated Clone Reentrancy|
|Ability to maintain state, such as in uninitialized shift registers||Maintains a single state across all instances—Non-reentrant subVIs share the same data storage among all instances.||Does not maintain state—Because each instance may use a different clone each time it executes, LabVIEW cannot guarantee that the data within a particular clone pertains to the same instance between calls.||Maintains state for each instance—Because each instance always calls its own reserved clone, the data in that clone always belongs to that instance.|
|Determinism for multiple, simultaneous calling VIs||Wait depends on calling VIs in line to execute—The time required for an instance of a subVI to begin executing varies with how many other instances are scheduled to execute before it.||Possible wait—Because LabVIEW allocates clones on demand, shared clone reentrant execution prevents calling VIs from executing deterministically.||No wait—All memory allocations occur upfront, providing deterministic memory usage and execution speed.|
|Memory usage||Lowest—LabVIEW allocates only a single data space for the subVI.||Medium—LabVIEW must allocate clones only for the maximum number of instances running simultaneously.||Highest—LabVIEW must allocate a clone for each instance of the subVI.|
|Note (FPGA Module) Shared clone reentrant VIs and preallocated clone reentrant VIs behave the same when used in FPGA VIs.|
Refer to the Asynchronously Calling Multiple Instances of a VI for Parallel Execution topic for information about asynchronously calling reentrant VIs.
Each clone has an individual front panel. To view the front panel while the clone is not running, double-click the instance of the subVI whose panel you want to view. You can also set the reentrant VI to open the front panel during execution. The title bar of the subVI contains (clone) to indicate that it is a clone rather than the original VI. To access the original VI from the clone, select View»Browse Relationships»Reentrant Original. You can also use the Front Panel:Open method within the subVI to programmatically open the front panel of each clone when it runs. The title bar of the subVI contains (clone) to indicate that it is a clone of the source VI.
You can interact with the front panel of a reentrant VI similarly to the front panel of a non-reentrant VI, particularly in the following ways:
The following two sections describe examples of reentrant VIs that wait and do not share data.
The following block diagram alerts the user when both his Lunch Time and his Break Time arrive. However, the reentrancy setting of the Alarm Timer VI is critical for producing accurate results.
|The user specifies a Lunch Time and a Break Time. For the purposes of this example, assume Lunch Time is 12:00pm and Break Time is 10:00am.|
|The Alarm Timer VI waits until the specified input time. Because the instances of the Alarm Timer VI appear in parallel parts of the diagram, it is impossible to predict which instance executes first. For the purposes of this example, assume the Lunch Time timer executes first.|
If the Alarm Timer VI is configured for non-reentrant execution, the Break Time timer cannot begin running until 12:00pm because it must wait for the Lunch Time timer to finish executing. This delay prevents the Break Time timer from triggering an alarm at 10:00am. Therefore, to ensure that both instances of the subVI can execute simultaneously and trigger their alarms at the appropriate time, you must configure the Alarm Timer VI to use one of the types of reentrant execution.
If you make multiple calls to each instance of a subVI that stores data, you must use preallocated clone reentrant execution. For example, you create a subVI, ExpAvg, that calculates a running exponential average of four data points.
Another VI uses the ExpAvg subVI to calculate the running average of two data acquisition channels. The VI monitors the voltages at two points in a process and displays the exponential running average on a strip chart. The block diagram of the VI contains two instances of the ExpAvg subVI. The calls alternate — one for Channel 0, and one for Channel 1. Assume Channel 0 runs first. If the ExpAvg subVI is not reentrant, the call for Channel 1 uses the average computed by the call for Channel 0, and the call for Channel 0 uses the average computed by the call for Channel 1. By making the ExpAvg subVI reentrant, each call can run independently without sharing the data.
(Real-Time, Windows) You can configure LabVIEW to either preallocate or share clones of a shared-clone reentrant VI within a Timed Loop or Timed Sequence structure. For example, if you place a shared-clone reentrant VI inside of a Timed Loop or Timed Sequence structure, you can set the structure to preallocate clones for instances of the reentrant VI you call within the structure. Instances of the reentrant VI that you call outside the structure continue to share clones. To set the allocation of a VI within a Timed Loop or a Timed Sequence structure, right-click the structure, select Shared Clone Allocation, and select one of the following:
To allow debugging on a reentrant VI, select File»VI Properties to display the VI Properties dialog box, select Execution from the pull-down menu, and place a checkmark in the Allow debugging checkbox.
To debug a specific instance of a VI with preallocated clones, open that instance of the subVI. Although you cannot edit the clone VI, you can use the block diagram of the clone for debugging purposes. For example, you can set breakpoints, use probes, enable execution highlighting, and single-step through execution.
To debug an instance of a VI that shares clones, apply breakpoints, probes, and execution highlighting within the source VI, not within the clone VI. Clone VIs do not maintain these settings across calls.
|Note When you debug applications and shared libraries, you cannot debug reentrant panels that an Open VI Reference function creates. You also cannot debug reentrant panels that are entry points to LabVIEW-built shared libraries.|