Button Press subVI

The sample code contains a simple button press subVI that was thrown in just to show how these sorts of things are done. If you start to use it in more than one place in your code, you will find that it doesn’t work very well. This happened at our shop last night.

The VI is not reentrant. This means that only one caller may execute the code at a time, and it means that state data, such as the feedback node that remembers the last call data, is shared across all calls. Basically, the side-effects of the call, where the previous data is stored, is modified by subsequent calls, and the next call will not work as expected.

The solution is to go to the VI Properties, Execution page, and set the VI to be preallocated reentrant.

Preallocated reentrant VIs allow for simultaneous calls and allocate state data for each caller at load time.

In case you are wondering what Shared reentrant VIs do, they allow for simultaneous calls, but operate a pool of state data storage that is as big as the number of simultaneous callers. This is great to save memory when you the state data is actually a temporary buffer and not call-site specific to the operation of the function.

In hindsight, it probably should have been made reentrant to protect the state data, but I never made a copy, so didn’t think about it.

Greg McKaskle