LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

enqueue and dequeue

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

Message 1 of 6
(3,050 Views)
Solution
Accepted by topic author carrot0322

Re: enqueue and dequeue

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
(3,033 Views)
Solution
Accepted by topic author carrot0322

Re: enqueue and dequeue

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.

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
(3,001 Views)

Re: enqueue and dequeue

Hi，
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
Message 4 of 6
(2,994 Views)

Re: enqueue and dequeue

@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.

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
(2,985 Views)

Hi,
Thank you.
I get it.
Best regards，
Carrot
Message 6 of 6
(2,975 Views)