LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Running subVI in parallel with itself using producer-consumer pattern

I'm using the procuder-consumer pattern to create what I call threads in response to various events much like in Producer Consumer with Event Structure and Queues

I have several physical instruments, and would like to run the exact same test in parallel on each of the instruments.  I have a subVI that takes as inputs a VISA resource and a few control references among other things and then performs the desired experiment.  I have a separate consumer loop for each physical instrument, with this subVI inside each consumer loop.

My test VI worked great; each consumer loop was a simple while loop incrementing a numeric indicator (not using my real subVI above).  However, my real program can only run one consumer loop at a time much to my dismay.  Reworking my simple test VI to use a subVI to increment the indicator rather than just explicitly coding everything resulted in the same problem: only a single consumer loop ran at a time (and as I stopped the running loop, another would get a chance to begin). The subVI in this case was extremely simple taking only a ref to the indicator and a ref to a boolean to stop, and incrementing the indicator in a while-loop.

Is there a way around this?  Now that I've spent the time making a nice subVI to do the entire experiment on on the physical instrument, I thought it would be fairly trivial to extend this to control multiple instruments performing the same experiment in parallel.  It seems only one instance of a given subVI may run at one time.  Is this true?  If it is indeed true, what other options do I have?  I have little desire to recode my subVI to manually handle multiple physical instruments; this would also result in a loss of functionality as all parallel experiments would run more or less in lock step without much more complexity.

Thank you.

0 Kudos
Message 1 of 3
(2,918 Views)
You need to make your subvi reentrant.  Then it can run several instances at any time with each instance occupying its own unique memory space.  Click on File - VI Properties - Execution, and check the reentry execution checkbox.  Then save the vi.
- tbob

Inventor of the WORM Global
0 Kudos
Message 2 of 3
(2,915 Views)
My mouse clicking finger thanks you immensley.  Works perfectly of course, thanks.
0 Kudos
Message 3 of 3
(2,910 Views)