01-17-2023 02:10 PM
Hi, I have two concurrent while loops: the first one is for enqueuing elements from data acquisition. The second one is supposed to run every second (lower speed) to process the enqueued elements which is writing them to a local file.
For some reason there is an unexpected behavior resulting in the accumulation of hundreds of elements in the queue without being dequeued, UNTIL the first DAQ loop is done. After that I can see the number of elements decreasing again.
How can I accomplish fully concurrent enqueue and dequeue of elements?
Solved! Go to Solution.
01-17-2023 02:57 PM
You seem to be asking; ‘If I enqueue elements faster than I dequeue them, why does the queue fill up?’
01-17-2023 03:16 PM
We can't help unless you attach your code. Queues will let you dequeue things immediately after you add them, so you likely have something preventing that in your code somewhere.
Attach it here and we'll take a look.
01-17-2023 03:26 PM
Yeah, my bad, I haven't seen it.🙄
01-17-2023 05:56 PM
A good option to help mitigate this is rather than dequeue a single data point flush the queue instead. It will give you all of the enqueued items in an array. Then you just process that array.
Another option is don't gate your processing loop with some arbitrary delay tat impacts the loop execution. Rather, dequeue elements as quickly as they arrive and place them into an array and then process that array at your desired intervals. This is basically a different implementation of the first suggestion as the end result is essentially the same.
01-18-2023 07:49 AM
@fflo wrote:
The second one is supposed to run every second (lower speed) to process the enqueued elements which is writing them to a local file.
The point of the Producer/Consumer is to be able to process the data as fast as possible when data is available. A consumer loop should never be time limited other than waiting for data to come in from the producer loop.
01-18-2023 10:43 AM
You state that the consumer loop only runs after the producer loop is finished. This would indicate a dependency between the output of the producer loop and the input of the consumer loop. THINK DATAFLOW.