05-02-2011 06:17 AM - edited 05-02-2011 06:24 AM
Hi!
What is the best way for the following:
I enqueu data in my producer loop. I need this data dequeue-d in both of my consumer loops, but I want to dequeu the same element in both loops.
Of course if I put dequeues in both loop, then the second consumer loop will loose the odd elements and the first consumer loop will loose the even elements.
thanks!
Solved! Go to Solution.
05-02-2011 06:28 AM
05-02-2011 06:48 AM - edited 05-02-2011 06:48 AM
just one more question:
My two consumer loops have a very fast loop cycle time, and the producer loop has a slow loop time (many GPIB reads).
In this case because there is no danger to loose data, Can I just replace the queue structure with Notifiers? So I do nod have to use two queues...
Thanks!
05-02-2011 07:16 AM
05-02-2011 07:18 AM
I see 🙂
The master loop has about 12 seconds loop time, and what I do in the two slave loops with the data, will take no more than 1 second.
Thanks very much for help! 🙂
05-06-2011 03:31 PM - edited 05-06-2011 03:33 PM
@Blokk wrote:
Hi!
What is the best way for the following:
I enqueu data in my producer loop. I need this data dequeue-d in both of my consumer loops, but I want to dequeu the same element in both loops.
Of course if I put dequeues in both loop, then the second consumer loop will loose the odd elements and the first consumer loop will loose the even elements.
thanks!
Makes very little sence- that is, the problem is stated in such a way as to preclude an informative response
Gerd wrote"
either create two queues or use notifiers...
Best regards,
GerdW
Usually, Gerd gives good advice but on this one I'm going to pick on him just a bit- I bet he rushed in just a tad without thinking about the premise of the OP's question - and Gerd I don't mean to sound mean, my appologies
The question pre-supposes that to use a queue element twice in parallel it must be read twice. This is false and led to less than optimal advice. What about a template like shown in this snippet?
We can certainly dequeue once and spawn as many independant actions as we need within a single consumer loop! Much more scalable than creating a queue for each action.
05-06-2011 03:39 PM
A notifier however is a very effective way to broadcast a message to multiple listeners. Notifiers also scale very easily.
05-06-2011 03:49 PM
Now I work with the notifiers, but thanks very much for the nice and simple idea with the queue! 🙂
05-06-2011 04:20 PM
@Mark Yedinak wrote:
A notifier however is a very effective way to broadcast a message to multiple listeners. Notifiers also scale very easily.
Certainly correct! and with the OP's situation where the consumers are faster than the producer a fine choice for now. when the relative speeds become closer the notifier solution can loose data. I intended to provide an alternate method for more general application. Thanks for the input
05-07-2011 09:40 PM
Everyone,
loose = not tight
lose = not found