Differences Between Reentrant, Templates, and Dynamic VIs

Updated May 2, 2018

Reported In

Software

  • LabVIEW Full
  • LabVIEW Base
  • LabVIEW Professional

Issue Details

When do I use reentrant VIs, template VIs and dynamically called VIs? What is the difference between each of these three types?

Solution

Reentrant VIs

Reentrant VIs are used when you want to run several instances of the same VI simultaneously. When the VI is not reentrant, there is one data space for the VI. Therefore, only one caller at a time can be running the VI, and so a caller may have to "wait its turn" to use the VI.  This is the default option for a VI, but you can set a VI to be reentrant. There are two types of reentrancy: shared and preallocated.
 
Shared Reentrant VIs

If the Shared clone reentrant execution option is selected, the VI has a pool of data spaces (same thing as a pool of clones). Initially only two clones are created when the calling VI begins. A caller will use one of these data spaces, but it doesn't know which one, and it may be a different instance on subsequent calls. When there are not enough data spaces (clones) in the pool for the number of simultaneous callers, new data spaces (clones) are created and added to the pool. Here the word "sharing" from "share clones between instances" means that the data spaces can be used by multiple callers over time. If there are 20 calls to the SubVI, but those calls happen such that at most two calls are going on at the same time, the pool will have only two data spaces in it and they will be "shared" among the 20 calls. Since only the necessary number of clones is created according to the current need, memory use is optimized. For quickest execution and best memory optimization, this option is recommended. 

Preallocated Reentrant VIs

If the Preallocated clone reentrant execution option is selected, each caller is given its own private data space (and clone). If there are 20 calls to the VI, 20 clones will be created and added to the pool when the calling VI begins. It may be that only two are ever busy at the same time if the calling pattern is like the one described above. If it is important that every call to a given instance of the SubVI use the same clone (for example, if the SubVI needs to hold data from call to call), then use this type of reentrant VI. Shared clones would not work because you would never know which instance of the SubVI last used the clone you are about to use, and the stored information would "cross talk" unpredictably between the SubVIs. The "preallocated" means that for every call, a data space and clone for that call is created. The preallocation happens before the VI runs. If you want to open multiple front panels of the same VI, reentrant SubVI options will not help.

If the VI you want to open multiple times is a top-level VI, you can duplicate the top-level VI on disk to a temp directory with a unique name and open the new file instance. It is not necessary to duplicate any SubVIs, only the top-level VI. You can then use the VI Server to open and run the copies.


Template VIs

You can make a multi-instance panel into a template VI, then open the file each time from the template. VI templates are VIs with the .vit extension. You can create a new VI from a template under File»New»Start from template. This creates a new instance of the VI, with its own memory space. These have distinct memory location when created and are just used as starting point for making another VI. You then need to configure whether that new created VI is or is not reentrant. 


Dynamic VIs

You can open both VIs and VI templates with VI Server. VI Server is used to dynamically load and run a VI. With SubVIs, the code and the data space of the SubVI are loaded when the top-level VI is loaded. When you dynamically load a VI, instead of using it as a SubVI and loading it when the main program is called, its code will not be loaded until the SubVI is called by the VI Server. This saves memory at startup time.

Additional Information

Complete the following steps to change a VI to reentrant:
 
  1. Navigate to File»VI Properties.
 
 
  1. Navigate to Category»Execution.
 
 
  1. Ensure that the Reentrancy option is set to Shared or Preallocated.
 

WAS THIS ARTICLE HELPFUL?

Not Helpful