最佳答案
将 VI 设置为可重入不会自动使其子 VI 可重入 - 如果这样做,这将破坏不可重入 VI 的一些用例,例如序列化对单个资源的访问或在调用之间维护存储的状态数据。因此,要决定子VI是否需要可重入,您只需考虑与决定父VI是否需要可重入时相同的问题。
我在 this post by GregR on the LAVA forum 中找到了有关注意事项的很好的总结。 ,据我所知,这仍然成立(完全可重入是预分配克隆可重入的旧 LabVIEW 术语):
- 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.
关于execution - 我是否应该将预分配VI中的子VI也设置为在LabVIEW中预分配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50288953/