LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

The best structure for a complex program


handre wrote:

 

 

I have one queue and two consumers, each looking at the queue. I enqueue 6000 numbered elements. Each element is enqueued twice, so there is: 1-1-2-2-3-3...6000-6000. After the end I expect to have elements from 1 to 6000 dequeued in each of the consumers. Right?


Wrong.  Read Nathan's reply #6 again.  You need to have two separate queues, one for each consumer.  Call them queue A and queue B.  So instead of enqueing item 1 into a single queue twice, you need to enqueue it once into A and once into B.  That way queue A contains 1, 2, 3, ....6000 and queue B contains 1, 2, 3, ....6.  Loop A will read queue A and get each value in order,  Loop B will read queue B and also get each value in order.

0 Kudos
Message 11 of 15
(1,156 Views)

Ravens Fan wrote:

handre wrote:

 

 

I have one queue and two consumers, each looking at the queue. I enqueue 6000 numbered elements. Each element is enqueued twice, so there is: 1-1-2-2-3-3...6000-6000. After the end I expect to have elements from 1 to 6000 dequeued in each of the consumers. Right?


Wrong.  Read Nathan's reply #6 again.  You need to have two separate queues, one for each consumer.  Call them queue A and queue B.  So instead of enqueing item 1 into a single queue twice, you need to enqueue it once into A and once into B.  That way queue A contains 1, 2, 3, ....6000 and queue B contains 1, 2, 3, ....6.  Loop A will read queue A and get each value in order,  Loop B will read queue B and also get each value in order.


 

Ditto Ravens Fan post!

 

You can think of queues as hoses that can be strung from one place to another. If you want your water (data) to go to two places, run two hoses.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 12 of 15
(1,151 Views)

mikeporter wrote:

This structure will work because when you have multiple processes attempting to dequeue data from the same queue, LV guarantees that only one process will see each item that gets enqueued. For example, say your acquisition code is in the producer loop and you have 5-6 consumer loops all monitoring the same queue. When the producer loop enqueues the first item, consumer loop 1 will see the data, but all the other loops will remain quiescent. Likewise consumer loop 2 will see the second item enqueued, loop 3 the third item enqueued - and so on. After the last consumer loop gets its item from the queue, the next item enqueued will again go to the first loop that is available and the cycle will continue.


Mike - I think it's this paragraph that was unclear in your original reply.  It implies that loops waiting on a queue will receive data in strictly round-robin order, which is not the case.

Message 13 of 15
(1,142 Views)

@ unclebump - the queue has length -1 (any length). I also could see that the number of elements can be bigger then 1.

 

@ nathand & Ravens Fan & Ben -> Thanks. The example was to check the mikeporter's information which I used in my program and I was loosing data. I have changed the code to multiple queues and it works very well now.

 

andrzej

 

 

0 Kudos
Message 14 of 15
(1,135 Views)

Yes, I see what you mean. There is no guarantee as to which loop will see a given item placed into a queue. Hence, you need to design your system such that each piece of enqueued data needs to relate to a single atomic operation.

 

Mike...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 15 of 15
(1,110 Views)