10-27-2006 04:10 PM - edited 10-27-2006 04:10 PM
I have an idea, whether this is feasible or not, I don't know.
Since you are looking at potentially a hundred queues, why not make a hundred queues by creating an array of queues? One queue for each consumer. Name the first queue 0 and put it in index 0 of the array. Next queue name 1 and put in index 1 of the array and so on.
If you have a message for consumer 5, select the element 5 of the array, and put the message into that queue.
Each consumer loop would select the appropriate element of the queue array for its dequeue functions.
Looping structures at the beginning of the programming should make it easy to create any number of queues. I don't know if there is any structural reason within LabVIEW this can't be done. Or an array of queues, if possible, would cause some memory management nightmare for the operating system.
Maybe it would not even have to be an array, just dynamically create all of the queues in an initialization loop and refer to them by an ID number for its name.
Message Edited by Ravens Fan on 10-27-2006 05:13 PM
10-27-2006 06:46 PM
10-27-2006 07:15 PM
JoeCAE wrote:
Kevin P.,
Actually, if I should preview, I would only preview the first element in queue. Since one of the consumer, being the destinator, will eventually pop out the element, it is okay. So that avoids using semaphore and simplifies the thing.
10-27-2006 07:21 PM - edited 10-27-2006 07:21 PM
Message Edited by Underflow on 10-27-2006 07:23 PM
10-27-2006 10:31 PM
Thanks Underflow,
I think we are on the same page. I just recently had LV Intermediate 1&2, where I first learned about queues. This thread really got me thinking about how to use queues cleanly, and also make the concept expandable.
I had to try out the concepts. I am attaching two VI's I created based on the Producer/Consumer DesignPattern (Data) example VI. They are showing just 2 consumer loops, but it could be expanded to any number.
In "ProducerConsumerData (Multiple Queues) Folder\ProducerConsumerData (Multiple Queue Array).vi" I created an array of queue references. So if you want a particular queue, you just use the array functions to index the array to that reference. The array was built using auto-indexing. And just one wire representing the array of queue refs is passed around the VI.
In "ProducerConsumerData (Multiple Queues) Folder\ProducerConsumerData (Multiple Queues).vi" I created multiple named queues. In one case, I used string functions to create "Loop0" "Loop1" .... "Loop(n-1)" as the names. In the other instance shown in disabled code, I used autoindexing to feed in any list (as string array) of arbitrary queue names. I think the advantage to either of these is that by using named queues, you don't have wires running to numerous loops (though I quess you should still have error wires to keep the order of execution). The advantage to the string array of queue names is that the queue names can be meaningful.
One thing I did learn by doing this is that using the force destroy option of the Release Queue VI was necessary for the VI to stop running since I obtained the queues a number of times by name.
10-30-2006 09:46 AM