LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

One Queues with multiple consumer

Solved!
Go to solution

I have several while loops. One of them is the one that puts data into the queue, this is, receive data from CAN and send it to a queue.

I have another loop that will process the data from the queue. My question is if is possible to add another parallel while loop to process the same queue? If I decode the queue in the other loop the same data is available in the new loop that I want to creat?

0 Kudos
Message 1 of 11
(5,982 Views)

Hi PM,

 


@PMSilva wrote:

If I decode the queue in the other loop the same data is available in the new loop that I want to creat?


No, you can only dequeue each element once!

A queue is usually used in "many producers, one consumer" scenarios. When you want to send the same data to several consumers you should use several queues…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 11
(5,966 Views)

It is possible to have multiple "Consumers" removing items from a Queue.  However, once an item has been removed, it is gone.

 

Here's an example of a situation I've seen.  A colleague was spooling data to disk (they were many 10-second videos, most of which he didn't want to keep).  He had multiple cameras running in parallel, so there was a lot of disk activity, with files being created and saved at the rate of a hundred files a minute.  To keep the disk from overflowing, he wanted to delete the 95% that didn't capture the Event he was trying to record.  He had a list of these files, put it in a Queue, and had a Consumer charged with deleting the files.  But the deletion was lagging the creation.

 

My original suggestion was to have 3 or 4 such Consumers working in parallel, all removing elements from the Queue and deleting the files.  This actually worked quite well.  But I also said "Why are you doing it this way?"  We worked out a much better method involving using circular buffers to hold a few seconds of video, enough to decide whether to start saving the images -- much more efficient than saving everything and erasing what we didn't need ...

 

Bob Schor

Message 3 of 11
(5,964 Views)

That was my first thought. The moment I read Queue, the element ceases to exist.Queue's behavior is the right FIFO type?

0 Kudos
Message 4 of 11
(5,940 Views)

OK. Makes sense. Thank you for the tips. I am still a new user of LabView. I will think of alternative ways to get around the situation.


It is possible to send a Queue from an open VI to another VI that I opened? If so, how can I do it?

0 Kudos
Message 5 of 11
(5,935 Views)

Hi pm,

 


@PMSilva wrote:

It is possible to send a Queue from an open VI to another VI that I opened? If so, how can I do it?


You can use named queues, so both VIs access the same queue...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 11
(5,918 Views)
Solution
Accepted by PMSilva

@PMSilva wrote:

I have several while loops. One of them is the one that puts data into the queue, this is, receive data from CAN and send it to a queue.

I have another loop that will process the data from the queue. My question is if is possible to add another parallel while loop to process the same queue? If I decode the queue in the other loop the same data is available in the new loop that I want to creat?


This partly depends on if you are OK with potentially missing some data points in one of the queues. You can use Preview Queue Element in one of the loops and it gives you the queue element without taking it out of the queue. Since timing between when the Preview Queue Element and Dequeue Element are not synchronized you can potentially get a repeated element or miss an element. For some applications this is OK.

0 Kudos
Message 7 of 11
(5,910 Views)

Ok,
Thanks all for your support. I will try to use the Preview Queue Element and pass the Queue via name to the other VI.
Thanks all!

0 Kudos
Message 8 of 11
(5,902 Views)

@PMSilva wrote:

I have several while loops. One of them is the one that puts data into the queue, this is, receive data from CAN and send it to a queue.

I have another loop that will process the data from the queue. My question is if is possible to add another parallel while loop to process the same queue? If I decode the queue in the other loop the same data is available in the new loop that I want to creat?


Queues are Many to One. Event are One/Many to Many.

If you want several reactions to some data, send it as an event. If you only have 1 listener it's basically the same as a queue.

There are some fringe cases where you can have several dequeuers, but since the elements gets consumed it must e.g. be irrelevant which consumer process it. I can imagine it as a simple way of parallellizing Consuming in the right circumstance.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 9 of 11
(5,888 Views)

How about having two Queues; Queue#1 from Producer to Consumer Loop 1 and Queue#2 from Consumer Loop 1 to Consumer Loop 2.  As elements arrive at Consumer Loop 1 (on Queue#1) they are dequeued for use in Consumer Loop 1 but also enqueued onto Queue#2 for use in Consumer Loop 2?

0 Kudos
Message 10 of 11
(5,872 Views)