LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to stop a parallel while loop when for loop is finished

Solved!
Go to solution

Hello all. I am relatively new to labview and have been trying to come up with a way to have my object continually get status while my for loop executes and then terminate when the for loop is complete. I tried putting it in a while loop outside the for loop but there is no criteria that I can think of linking its completion with the completion of the for loop. Also, there is no status that the object calls that I can use to terminate the while loop. It needs to stop when the for loop is finished. Any help would be much appreciated and a snip example would be even better. I have tried so many different ideas but with no success.

0 Kudos
Message 1 of 16
(3,061 Views)

Instead of all these greedy loops ( do you really need to update that indicator millions of times per second or check millions of times per second if a timer has elapsed?), think about a good architecture. (e.g. a state machine. Most likely you can eliminate all that duplicate code.

 

What does the program do?

 

Unfortunately you only attached a truncated picture, so we cannot really give more specific advice. Typically people get better help if they attach an actual VI.

0 Kudos
Message 2 of 16
(3,053 Views)
Solution
Accepted by topic author Jeffk2336

Look up Notifiers in the LabVIEW example finder.

 

Your Elapsed Time Express VI in the inner while loop should really have a small wait.  Right not it is burning a CPU core at 100% for 5 seconds polling that status of a timer.  A wait function of 5000 milliseconds (in a sequence frame or using the new Wait.vim) would do the same thing and not burn the CPU.

0 Kudos
Message 3 of 16
(3,049 Views)

I will look up notifies and see if I can implement it successfully. Thank you for the tip, hopefully they're some good example online. The elapsed time does need to be at least 5 seconds because the object I called before the wait time takes a bunch to time to process in the system I am working with and I need to check status after at least 5 seconds has elapsed. Is there another wait time method that uses less of the CPU..?

0 Kudos
Message 4 of 16
(3,031 Views)

Yes.  The Wait (msec) function in the time palette.  Replace the while loop with a sequence frame, and put the wait function in it.

0 Kudos
Message 5 of 16
(3,025 Views)

Thank you for the response. I will change it.

0 Kudos
Message 6 of 16
(3,004 Views)

It was suggested by someone in the community to look into notifiers if I wanted to stop a while loop after a for loop finishes its iterations. I have tried a bunch of combinations of logic that simply do not make sense nor work. I have attached a vi but it is just a shell (it is just a place holder, I know it cannot work as shown). Is there a straight forward non trivial way to accomplish this utilizing notifiers?

0 Kudos
Message 7 of 16
(2,979 Views)

You need a timeout on the Wait on Notification, even a value of 0, so it can execute.

The Release Notifier belongs after the while Loop.

You need to enable Automatic Error Handling on your VI (VI Properties >> Execution)

 

Because your Master Loop kills the notifier right after it ends, the slave loop doesn't see it.  Because you didn't have automatic error handling turned on, you didn't see an error message about the notifier reference going bad.  It's like you shot the messenger immediately after giving him the message to send.

Message 8 of 16
(2,925 Views)

Ha!  You brought new meaning to the old phrase, "don't shoot the messenger".  I like it!

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 9 of 16
(2,913 Views)
Solution
Accepted by topic author Jeffk2336

(With a username of Jeff k, make sure you are not getting confused with this guy :D) 

 

Can you place your construct in the overall context of the entire program? This entire thing still seems way too convoluted. Why would you need to send a notification with every iteration of the FOR loop? Shouldn't' you while loop stop when the notification is NOT "Loop 1"? One notification after the FOR loop would be sufficient.

 

It would even be sufficient to never send any notification and use the killing of the notification to stop the while loop.

 

twoloops.png

 

I stand by my statement that there are probably much better ways to do whatever you need to do. Once we know the overall architecture, we can probably offer suggestions.

Message 10 of 16
(2,897 Views)