LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

What is the best way to run multiple class instances containing infinite while loops?

Solved!
Go to solution

Hi,

 

I have a multiple class instances (say a, b, c,...) that have the same parent and I want to run the same overridden methods to all instances in parallell.

 

For example:

a.init() -> a.run() -> a.stop() -> a.run() -> a.stop()   ->

b.init() -> b.run() -> b.stop() ->           ->               ->

c.init() ->           ->             -> c.run() ->               -> c.stop()   

...

 

See attachment for details.

 

The problems now are:

1. the "run"-method does not return until it receives external trigger

2. all run methods return in a different time

 

Bullet 1 means that I cannot use autoindexed for loop because in this case b.run() has to wait until a.run() finishes, right? Is there a way to run for loop in parallel?

 

Bullet 2 means that a one object has to be able to run and stop independently of others.

 

What is the most elegant solution? The copy-paste solution seen in attachment works for 3 instances but currently there are 10 and more is coming.

 

Juha

 

 

0 Kudos
Message 1 of 3
(2,660 Views)

You need to make your methods reentrant. Any methods that are shared that will take any significant amount of time to complete should also be reentrant. Very simple methods can easily be shared since they will not result in siginificant delay if called at the same time. Reentrant methods (VIs) will be able to run completely independent of each other and in parallel.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 2 of 3
(2,643 Views)
Solution
Accepted by topic author jhkoivis

Actually, what I wanted to know was "How to add the "P" to for-loop"... Easy, after you ask the right question.

 

In the attachment, there is a test.vi that has two numeric indicators in an infinite while-loops. If I allow parallelism, both of the numeric are incremented infinitely. If I don't allow parallelism, only the first one is incremented (as it never leaves the infinite while loop). 

 

To solve my original problem, I can make one init-run-stop branch inside an indexed-parallel-for-loop and just make sure that there is the same number of loop instances as there is objects in my object array ( object array is the one autoindexed in for-loop).

 

Also good point about the reentrant vis. I must add that also.

Download All
0 Kudos
Message 3 of 3
(2,630 Views)