I jusr found a interesting question, which also confused me a lot. Hope you can help me. Look at the picture(panel and block diagram). when I press the dequeue loop stop button,the number will change to be 50. when I press the enqueue loop stop button ,then press the dequeue one, the number will never change to 50. I really cannot understand. Moreover,on the basis of the second operating sequence, what I can do to jump out the dequeue loop and change the number??
Solved! Go to Solution.
your enqueue and dequeue loop are running at almost same rate ( which is crazy because you have not put any wait in enqueue loop.)
So when you press dequeue loop stop button it dequeues one element and stops and you go to other sequence and get value = 50.( Note that you are still enqueuing the data )
When you press enqueue loop stop , the dequeue funtion had already pulled out data from queue and waiting for other data. Because the dequeue timeout is -1 it will wait forever and the loop will not stop and you would not get any value outside the loop.
For a workaround you can give some timeout to dequeue function.( just a workaround , may be not a good technique )
Explanation done now what actually you are trying to do with this??
Your lack of a timeout is why it is stuck there.
Instead of a second stop button, what you should do is somehow send a command to your consumer loop to tell it to stop. Something like +INF or NaN are common things to try.
And you need to release your queue once the consumer loop is done.
First，I am now writting a DAQ program. In order to have the data acquisition (the enqueue loop) and the data processing(the dequeue )can be synchronous, I have the enqueue and dequeue the same rate.
Again, that doesn't make much sense. Your producer loop should run at whatever it needs to, based on how fast you are aquiring data from the DAQ. The consumer loop will iterate based on when data is in the queue. If there isn't data in the queue, then it sleeps until there is data.
Secondly, I have to stop the enqueue loop because there may be some element wait in enqueue loop. So I wait all the elements dequeue, then stop the dequeue loop .
That's why I said to put a command of some sort into your queue when the producer loop is done. When the consumer sees that command, it knows to stop. This will ensure you have processed all of your data.
Thirdly, like the number part after the dequence loop, there are still some processing modules which need all the processing result arrays generated in the dequence loop.So here I put a number control to illustrate. You may think that I can put the rest processing modules into the dequeue loop. But these processing modules are time-consuming and memory-consuming，the buffer will overflow.If you have any advises，please contact me.
Nothing says you can't use yet another loop to do that processing.