LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to end consumer loop

I am using producer/ consumer pattern to separate data acquistion and processing. The consumer loop is much slower than the producer loop. If I put "release queue" outside of the producer loop to stop the consumer loop, the consumer loop can just run once. But I need consumer loop to run same times as producer loop. So I did not use the release queue to stop the consumer loop but used the error connecting with  "stop if true" in the consumer loop. The producer loop and consumer loop are in a sequence structure. It seems that the sequence contains producer/consumer loops can never finish to enter into the next sequence. I think that producer loop and consumer loop have all stopped because their iteration numbers stop increasing at certain time. But the vi can never go into the next sequence. So I am very confused about that. If I put "release queue" outside of the producer loop to stop the consumer loop, the vi can finish this sequence and go into the next sequence. Do anyone know how to solve the problem?
0 Kudos
Message 1 of 4
(3,040 Views)

I got a little bit confused as I read towards the end of your paragraph.  Perhaps you could post your VI so we can have a clearer idea how your loops are setup now.

 

In my opinion, the best way to stop the consumer loop is for the producer loop to pass it a "stop command" as part of its message queue.  That way the queue still exists so that the consumer can continue processing all of the data in the queue.  When it hits the final queue item of the stop command, then it executes a case structure that stops the consumer loop.  Then the consumer loop can release the now empty queue.

Message 2 of 4
(3,020 Views)
Thank you for trying to help me. I attached part of the vi containing the producer/ consumer loop. The upper loop is the producer loop and the bottom one is consumer loop which process each buffer. ATS Aysnc produce buffers as queues. I do not think it is good to pass a stop command from the producer loop. The producer loop is much faster than the consumer loop and it does not know when the consumer loop will end processsing all queues. Is there a way to make consumer loop and producer loop ends atomatically when the consumer loop ends processing all queues?
0 Kudos
Message 3 of 4
(2,999 Views)

Sophia,

 

The idea of passing the stop command via the queue is that it will be at the end of the queue - after all the data.  The consumer loop will see the stop command after it processes all the earlier data. In this case it might be better called "End of Data" rather than "Stop." 

 

The sequence structure is totally unnecessary.  Use dataflow to handle the initialization and  completion code.  The sequence structure will definitely proceed to the next frame when all the code within the current frame completes execution.  If the iteration counts have stopped increasing it may mean that the loops have stopped running or that the producer is blocked, waiting for something within it to finish so it can go to the next iteration.  It is also possible that the consumer loop has started an iteration but no data is in the queue.  Since the timeout is default at -1 the Dequeue will wait forever for data.

 

Please look at the style guides.  Use left to right wiring and avoid hiding wires behind other objects.  Also try to keep the diagram to the size of one screen.

 

Parallel loops should always have some kind of wait or delay to allow CPU resource sharing.  In the producer loop the data acquisition VI may provide that function.  In the consumer loop the easiest way to get a delay would be to change the Dequeue wait time to something other than -1.  You also should check the Dequeue Timed out? line if you use timeout for the delay.  If it is true, then the data is not valid and should not be analyzed in the for loop.

 

You probably only see the last of the 10 spectra. Unless the datasets are rather large, the loop will probably run too fast to see the others.

 

Lynn 

Message 4 of 4
(2,986 Views)