Reentrant VI

In the subVI post, when we are talking about re-usability we mean that the subVI can be reused multiple times in the same diagram or in different diagrams. what happens when a subVI is called from several locations in a diagram simultaneously?

By default, a subVI is non-reentrant . Only one caller can access that subVI and therefore one instance of a subVI can run at a time. This is because LabVIEW allocates only one dataspace in memory to store data of this subVI. The rest of the callers have to wait for their turn. When such a subVI has an uninitialized shift register, it acts like a buffer and stores data between calls. Such  subVI’s become functional global variables which are used to hold global data.

To simultaneously execute multiple instances of a subVI, the subVI has to be made reentrant. In reentrant execution, LabVIEW creates clones of the subVI that have different locations to store their data. A subVI can be made reentrant by selecting Execution category from VI Properties window as seen below. Short cut for VI Properties is ‘Ctrl+I’.



There are two types of reentrant executions

1. Pre-allocated clone reentrant execution: Separate clone is assigned for each instance of subVI. Every clone is independent and has separate dataspace. State information can also be maintained for each state because data in that clone belongs to that instance.

2. Shared clone reentrant execution: Pool of clones are created to share. State information is not maintained because each instance may use a different clone in subsequent execution. The clones will be deallocated only after the associated VI is unloaded from the memory. When a shared clone reentrant vi is called in a timed loop, the timed loop will pre-allocate clone. Since timed loops are used when deterministic timing is required, clones are pre-allocated to prevent spending time in allocating a new clone to pool .

Leave a Reply