LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

enqueue and dequeue

Solved!
Go to solution

Hello everyone,

    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??

0 Kudos
Message 1 of 6
(5,728 Views)
Solution
Accepted by carrot0322

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??

 

Message 2 of 6
(5,711 Views)
Solution
Accepted by carrot0322

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 6
(5,679 Views)
Hi,
Thank you for your reply.
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.
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 .
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.

Best regards,
Carrot
0 Kudos
Message 4 of 6
(5,672 Views)

@carrot0322 wrote:
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.

 

 


@carrot0322 wrote:
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.

 

 


@carrot0322 wrote:
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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 5 of 6
(5,663 Views)
Hi,
Thank you.
I get it.
Best regards,
Carrot
0 Kudos
Message 6 of 6
(5,653 Views)