LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Parallel while loop dequeue

I have three parallel while loops with queuing. Every second I enqueue the loop count. When I dequeue the value in the bottom loop I only see every even number when I monitor the element with a debug probe. Why wouldn't I see every value?

 

Thank you.

0 Kudos
Message 1 of 25
(5,493 Views)

@mperlick777 wrote:

I have three parallel while loops with queuing. Every second I enqueue the loop count. When I dequeue the value in the bottom loop I only see every even number when I monitor the element with a debug probe. Why wouldn't I see every value?

 

Thank you.


You can't dequeue a que in two places.  Whoever wins the race will get to dequeue the data.  Everyone else loses.

 

While you're at it, you can delete that sequence structure.  All it's doing is giving me heartburn.  😉

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 2 of 25
(5,488 Views)

Hello mperlick777,

 

As you noted, you have two loops dequeueing elements from a single queue.  Based on the behavior you've observed, it sounds like your consumer loops are each pulling out every other element sent by your producer.

 

Once you dequeue an element, it's no longer available for other dequeue operations.  Multiple-reader architectures are usually used with queues when you're trying to parallelize processing of data and each element can be operated on without affecting others.

 

If you're looking for a way to broadcast messages to multiple locations, I suggest you take a look at Notifiers.

 

Best Regards,

 

 

Tom L.
Message 3 of 25
(5,486 Views)

Thank you Tom. Now I see what's happening. I'll need to look into notifiers so both consumer loops will be triggered with the same message.

0 Kudos
Message 4 of 25
(5,456 Views)

But if you need all pieces of data to go to all loops, you will still need to use queues.  (Notifiers are only good for holding 1 piece of data.)  You just need to have 1 queue created for each of your consumer loops, and enqueue the same data in all of the queues.

Message 5 of 25
(5,448 Views)

Notifiers dequeue the latest element arriving on the queue.  Notifiers hold timestamp information within the wait on notifier and all waits on the same notifiers may each recieve the same notification.   This is different from queues and is what makes the Notifier more suitable for one-to-many interprocess communications.

 

The down side of notifiers is that they can be "Lossey"  they can only recieve the latest Notification (With starting exceptions) so if the producer is enqueueing "commands" that can be a problem- with "Data" its a question of design and with "State" it is no problem.

 

 Without seeing you implementation it is hard to advise you.  But, if you draw out your communications map, and it has a lot of crossed wires- you probably have enough information to revise it and avoid problems.


"Should be" isn't "Is" -Jay
0 Kudos
Message 6 of 25
(5,440 Views)

I see the only downside with notifiers is that I may miss one if a vi doesn't finish before it recieves the next notifier. I may need to have two queues to make this work. The sample code I sent was a pared down version of the code I'm running to allow others to run it. The second loop in my actual app might not finish in time to receive the notifier.

0 Kudos
Message 7 of 25
(5,396 Views)

If the data transfered must be "lossless" a notifier is not the right answer.  If the transfer is one-to-many a queue is not the right answer.

 

"Lossless" "one-to-many" solutions require multiple queues (or some roll-your-own pseudo buffer but that is usually not needed)


"Should be" isn't "Is" -Jay
0 Kudos
Message 8 of 25
(5,388 Views)

If it helps, you can bundle all your queue refs together.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 9 of 25
(5,380 Views)

I don't uderstand why there are three loops.

 

Use one queue and only two loops. Keep the producer loop, but combine the code of the two consumer loop into one. Place the code of the current third loop inside a case structure that turns to a blank state after a certain number of iterations to duplicate the current functionality.

 

Also clean up the code so it can be shutdown in a reasonable way. Currently it can only be aborted.

0 Kudos
Message 10 of 25
(5,371 Views)