LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

producer consumer loop processing question

Hi,

I have a producer/consumer loop design in my application. The producer enqueues data at the opposite end to achieve a LIFO stack like characterstic. The problem is that the consumer loop processes data faster than the producer consumer loop can process. I would like the consumer to consume in the last entry that the producer places into the stack. The problem right now is that the consumer starts consuming before the producer is finished with everything, so there are still data being placed onto the stack after the consumer loop starts going. Does anyone have any ideas how to solve this problem.

Thank you,

-Tim
0 Kudos
Message 1 of 4
(2,792 Views)
What are you using for a stack?  If you are using a queue, your consumer loop can check if the queue is empty.  You could go into a loop where you wait until data is in the queue before processing it.  Just check the queue for data in a loop.  If no data, do nothing, if data, exit the loop and process.  Put a delay in the loop, probably 10mS would do.  Then your consumer would not be trying to process nothing.
- tbob

Inventor of the WORM Global
0 Kudos
Message 2 of 4
(2,792 Views)
Also, if you attach a snippet of you code, then that would be helpful.
 
Regards,
Chetan K
Application Engineering
National Instruments
0 Kudos
Message 3 of 4
(2,768 Views)
Expanding a bit on tbob's suggestion: Set a timeout on the queue. Test the Timeout? output. If true, no data was received. If false process the data. The timeout becomes the delay/wait.

Also, can you process the the data in chunks rather than one at a time?

Lynn
0 Kudos
Message 4 of 4
(2,753 Views)