03-04-2011 04:11 PM
Is there an easy way to make subVIs reentrant if their calling VI is reentrant? I just realized I have a VI managing TCP/IP connections, and it's running in parallel but was not made reentrant. Inside it are a few subVIs that build the data packets to send. While it is not terribly difficult to manually change all subVIs, is there a way to make subVIs all reentrant also?
03-05-2011 11:26 AM
Well, the VI class has both a Callees[] property and an IsReentrant property, so you can certainly write some simple VI server code which will do this recursively, but it will almost certainly be faster (and safer) to do this manually because you would have to be careful at where to stop and which VIs not to do this to.
You could probably do this more easily if you go over the hierarchy of files directly, but that depends on all your VIs being in one place with no other VIs being there.
03-05-2011 11:44 AM
I agree with tst, you do NOT want to do this willy-nilly. Having some automatic convert-to-reentrant gizmo would undoubtedly convert something to reentrant that you didn't want to.
Best to apply the old gray matter to it.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
03-05-2011 04:46 PM - edited 03-05-2011 04:47 PM
@tst wrote:
Well, the VI class has both a Callees[] property and an IsReentrant property, so you can certainly write some simple VI server code which will do this recursively, ...
And - display the VI names! a quick checkbox array will give you control over which VIs to make re-enterant and which you would be better off leaving alone![]()
Of course TEST your auto-reenterant vi on a dummy project. wouldn't want a bug to cause lots of new ones![]()
03-07-2011 08:06 AM
Be aware that indiscriminately making a lot of code reentrant could also dramatically increase your memory use. Note that there are several flavors of reentrant to address this very problem. Read up on them in the LabVIEW help before proceeding. I have seen a program halve its memory use due to fixing reentrancy problems.
03-07-2011 09:45 AM
Thanks for the tips, everyone. I will proceed manually, but sounds like it might be time to add something to the tools menu for this. I really like the checkbox idea, Jeff.
03-07-2011 10:03 AM
sounds like it might be time to add something to the tools menu for this.
I don't see why. In your case, you said:
I have a VI managing TCP/IP connections, and it's running in parallel but was not made reentrant. Inside it are a few subVIs that build the data packets to send.
The two features of re-entrancy are 1) separate data spaces for local variables for each instance, and 2) the ability to interrupt execution of instance A and proceed with instance B, then return to instance A (which requires #1).
I've done work managing connections, and my scenario requires one and only one VI being reentrant. It's hard for me to picture a need for enough different VIs being reentrant to justify another tool.
Just my 2 cents.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
03-07-2011 12:16 PM
Actually, I have already taken your advice and just made the top level VI reentrant. However, it shouldn't be too difficult to build a tool for this and may be nice to have in the future, even though I won't be using it in this case.
That said, does anyone know why the attached VI errors out where I have circled it in red on the BD? This is more of a recursive call issue then an issue that I have asked about in the original post.
03-07-2011 12:25 PM
@for(imstuck) wrote:
That said, does anyone know why the attached VI errors out where I have circled it in red on the BD? This is more of a recursive call issue then an issue that I have asked about in the original post.
I guess I have to leave the references open until it's all said and done. However, can someone explain why? Why does it need these unused references in subsequent recursive calls? Or is it using them. I have a feeling I'm just not understanding what's happening in the background.
03-07-2011 12:46 PM - edited 03-07-2011 12:47 PM
@Jeff Bohrer wrote:
@tst wrote:
Well, the VI class has both a Callees[] property and an IsReentrant property, so you can certainly write some simple VI server code which will do this recursively, ...
In 2010 I don't see the "Callees" property. I just see callers. I did find another VI that has it but the property node is a pinkish-red color