08-11-2011 08:56 AM
I am new to labview and a problem running two queues as producers/consumers, see sample VI. I am inserting data first into the first queue, later into the second queue and want to process the data later in the consumer loop (comparing data 1 with data 2). What am I missing??
Thanks
Thomas
Solved! Go to Solution.
08-11-2011 09:11 AM
Thomas,
if producer and consumer are the same loop each (like in your screenshot), there is absolutely no sense to create two queues. Just use a single one.
The problem is that you have to feed both queues and dequeue both queues in order to keep both loops running.
hope this helps,
Norbert
08-11-2011 09:14 AM
Sorry, I forgot to mention, that the data sets for the two queues are not the same. The data for queue 1 is from one source and the data for queue 2 is from another source. Once I have both sets of data, i want to compare the data in the consumer loop.
Thomas
08-11-2011 09:23 AM
Ok, but still, if you have two queues in a single loop without timeouts, you have to have the same amount of elements in both queues, otherwise the "bigger" one will run full (leading to out of memory errors).
So if the consumer reads from two different queues, use a timeout for each read. Make sure that you do not compare if one of the reader ran into timeout.
All in all, i am not sure if you are trying the best setup here. As stated above, queues are not the best thing to use multiple times in a single loop.....
Norbert
08-11-2011 09:29 AM - edited 08-11-2011 09:34 AM
The consumer loop will not iterate until both queues receive data. Each consumer needs it's own loop. To compare data in the two consumers you have to send the results of both back to some other process (a fourth queue or even back in your producer)
[Edit: Saw Norbert's reply only after I hit post]
08-11-2011 09:50 AM
Another idea would be something like this. Please note that you should insert some timing, otherwise you will produce 100% CPU load for a core.
Norbert
08-11-2011 09:54 AM
You should also set the queue sizes to 1. Otherwise you have to take into account what would happen if one queue has three elements and the other has two. You might end up out of sync and compare the wrong elements.
08-11-2011 09:58 AM
Good idea, Steve. This will simplify the consumer since you can leave both queues to a simple dequeue. You can stop execution of the consumer by simply close the queues which will create an error in the appropriate dequeue function (so error handling to stop the consumer is important!).
Nevertheless, it arises a new question: What are you going to do if you try to enqueue something into a full queue?
Norbert
08-11-2011 10:12 AM
If your are simply doing basic messaging with two different types of data you can define your queue element to be a cluster which includes a message type/ID and a variant. That will allow you to use a single queue for the consumer but handle differetn types of data. This assumes teh messages are independent. If your system requires both messages/data sets to arrive before you can process anything then some of the earlier suggestions will work.
08-11-2011 10:20 AM
Here is a way to dequeue from two loops. The timeouts are set on each Dequeue function and are monitored by the case structures connected to the "timed out?" booleans. Use of Bulid Array in a loop is not the best practice because of memory allocation issues, but it is the easiest way to show the concept of handling two queues. The timeouts do not need to be the same, but each dequeue will only operate once per iteration of the while loop, so different timeouts may not be very meaningful. Both case structures are identical.
Lynn