01-30-2009 09:34 PM
I have a design pattern where a timed loop does some processing. I need to instantiate this pattern several times -- in fact, the number of times is determined at run time via a config file. But how can I create a timed loop programmatically and have them run in parallel? In any other language/OS, I can simply create a thread on-the-fly but I don't see a way to do that in a VI.
01-30-2009 10:38 PM
You can take any VI and give it the extension VIT. This makes it a VI template. Opening this template programmaticly using VI server and you get a separate instance of the code that runs independently, each time you open it.
Mike...
01-31-2009 12:02 AM
01-31-2009 04:49 AM
The vit is just a sub-vi. It works according to your code. The "vit" just forces the opening of multiple sub vis with the same block diagram.
Another option is to make your sub vi reentrant and call it, as shown.
see this
01-31-2009 09:08 AM
Yes, I VIT does not block because the VIT file extension causes LV to load a completely new instance of it into memory when it is opened. This is how you can spawn a new process in LV.
Mike...
01-31-2009 06:24 PM
So ... a VIT is just a cleaner way of calling a reentrant sub-VI without waiting for it to return?
Before I dive into this, does anybody know if either of these approaches will work on a RT PXI target?
Thanks.
01-31-2009 07:20 PM
Don't know which would be better from the standpoint of RT, but they both should work. One other difference between a VIT and a reentrant VI is that you can debug a clone coming from a VIT, where as you can't debug an individual instance of a reentrant VI.
Mike...
02-01-2009 11:00 AM
I have a design pattern where a timed loop does some processing. I need to instantiate this pattern several times -- in fact, the number of times is determined at run time via a config file. But how can I create a timed loop programmatically and have them run in parallel? In any other language/OS, I can simply create a thread on-the-fly but I don't see a way to do that in a VI. |
I'd put the Timed loop in a VIT as suggested above and run the VIT's in parallel by spwaning off background threads using VI server.
If you can put an resonable upper limit on the number parralel loops you could use a case structure with the appropriate number of the re-entrant VIs in each case and then LV would do all of the work and create the threads on-the-fly in your behalf.
Couple of notes:
Last time I looked RT-OSs are not known for returning allocated resources. So I would tred carefully into a design that is repeatedly creating threads. Detemining the proper number at boot and staying with that is OK. Just don't do it in a loop or you could end up running out of memory.
This Nugget includes code that creates a bunch of processes from a template.
Mike wrote
One other difference between a VIT and a reentrant VI is that you can debug a clone coming from a VIT, where as you can't debug an individual instance of a reentrant VI.
Sorry Mike but I have to split hairs and say that is partially right and patially wrong.
You CAN debug an individual instance of a re-entrant VI ....
by identifying which instance you want to debug. This can be done by single stepping the caller and clicking "step-into" which will open that instance.
You CAN NOT debug an individual instance of a re-entrant VI ....
and click the "Stop" button while debugging the re-entrant sub-VI and expect to retain un-saved changes, since LV will crash (last time I checked). You should back out of all sub-VI calls first.
Ben
02-02-2009 08:36 AM