LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Producer/consumer third loop stop problem

Solved!
Go to solution

Hello everyone,

I need help, I am unable to stop the third loop in my consumer producer loop. I have attached an image of what the code looks like in the stop section. I just recently started using producer/consumer loops so please if you see mistakes let me know so I can correct them as well. My even starts properly and my second while loop which handles DAQ signals works as well but my third loop does not stop.

0 Kudos
Message 1 of 13
(3,448 Views)
Solution
Accepted by topic author rake615

Try send 2 stop events, one for each loop.

 

George Zou
0 Kudos
Message 2 of 13
(3,439 Views)

You may have a race condition.

 

You are checking the status of your queue and then dequeuing the element in the middle loop. If that dequeue happens before the status is read in the lower loop, you have lost your message.

 

There are other things that could be improved in the picture you sent

1.) Not sure why in the second loop you just don't wire the dequeue item directly to the case structure.

2.) If you have a stop case, you do not need a local variable, just wire a true to stop.

3.) The exit LabVIEW vi is bad news. Do not use.

 

mcduff

Message 3 of 13
(3,415 Views)

1. No need for the Queue Status in any of your loops.  Even in your consumer, you are just going to dequeue the stop command.

 

2.  There is a technique for your state machine where the Event Structure surrounds the state case in the Timeout case.  You can use that to combine your first and third loops.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 13
(3,381 Views)

You could use a Notifier, sending "True" when the Stop button is pushed, and doing a Wait on Notification, with Timeout set to 0 (so you get the default value, False, if there is no Notification, and True if Stop had been pushed) on all of your "listening" loops (you have 2, but it also works for 20).

 

You posted a picture instead of code (a topic that occasionally causes me to rant and rave), so I can't tell if you are using LabVIEW 2016 or 2017, so I won't even mention Channel Wires ...

 

Bob Schor

0 Kudos
Message 5 of 13
(3,351 Views)

Sorry, I wasn't able to upload original VI since it has company "classified" information. I have the removed the vi's I could not share and upload the code.

0 Kudos
Message 6 of 13
(3,314 Views)

Thank you, I did have a true constant originally in the stop cases but since it didn't work I tried local variables which I think make it worst. Have removed variables and placed true constants, also got rid of the exit labview and have connected the dequeue element directly to my second loop.  I agree with the race condition I just don't know how to fix it. Never worked with third loops in the producer consumer before, I barely know how to do two loop 😞

0 Kudos
Message 7 of 13
(3,312 Views)

I will try to look at this later, right now busy with my real job.

 

Some thoughts.

 

You may want to refactor your code. You have one place where in enqueue your command and two loops where you dequeue the command. As of now you do not know which loop dequeues the command. Once the command is dequeued it is unavailable to the other loop. You can use Notifiers, but commands may be lost which I think you do not want. You can try Channels also.

 

mcduff

0 Kudos
Message 8 of 13
(3,303 Views)

crossrulz, I have been trying to understand more about your suggestion. I have attached an image I found in the ni forums to understand and see if that is what you mean. 

0 Kudos
Message 9 of 13
(3,284 Views)

@rake615 wrote:

crossrulz, I have been trying to understand more about your suggestion. I have attached an image I found in the ni forums to understand and see if that is what you mean. 


EventReinit

 

I do not know where you got that image from but with no timeout value wired it will never timeout.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 10 of 13
(3,276 Views)