问题
I have got a VI which execution type is set to be as preallocated clone reentrant. In the VI i have several SubVIs. Should I set the execution type of SubVIs the same as in the main VI?
Thank you
回答1:
Setting a VI to be reentrant doesn't automatically make its subVIs reentrant - if it did, this would break some of the use cases for non-reentrant VIs, such as serialising access to single resources or maintaining stored state data between calls. So to decide whether a subVI needs to be reentrant, you just have to consider the same issues as you did when deciding whether the parent VI needed to be reentrant.
I found a good summary of the considerations in this post by GregR on the LAVA forum, which still holds true as far as I can see (fully reentrant was the older LabVIEW term for preallocated clone reentrant):
- Any VI that maintains state needs to be either non-reentrant or fully reentrant depending on its requirements for that state.
- If there are any VIs that truly can't be called at the same time, those should stay non-reentrant. This could be things like configuration dialogs or file modification. Non-reentrant VIs are one of the easiest ways to serialize access to single instance resources.
- Any VI that is part of a performance critical code path probably should be made fully reentrant. This avoids synchronization points between multiple parallel instances of performance critical code or non-performance critical code getting in the way of performance critical code.
- Beyond that you can start to favor non-reentrant or shared reentrant to reduce memory usage.
- [...] VIs that always execute quickly can be considered for leaving as non-reentrant. Keep in mind that there is a difference between a VI that always executes quickly and one that typically executes quickly. Anything that does asynchronous communication (networking, queues, ...) should be considered slow, because it could take longer than expected.
- Making VIs that are called from a lot of places shared reentrant instead of fully reentrant will slightly increase execution time but can greatly reduce the number of instances required and thus memory usage.
来源:https://stackoverflow.com/questions/50288953/should-i-make-subvis-in-preallocated-vi-as-preallocated-too-in-labview