LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

producer/customer architecture sync

I built a producer/customer architecture type code and I ran into the problem that if the producer loops ends normally [because it produced the specified amount of data], it kills the queue as well so the consumer loop cannot output the data which is still in queue because the queue is destroyed - data is lost.

 

How is it possible to syncronise the two loops, how can I make the VI wait until the consumer empties the queue?

 

Thanks,

Krivan

0 Kudos
Message 1 of 20
(3,918 Views)

Use a notifier or user event in the consumer to communicate back to the producer that it is done. You can use the queue status function to check how many items it contains.

=====================
LabVIEW 2012


Message 2 of 20
(3,908 Views)

I discussed this issue in my community nugget.

 

Felix

Message 3 of 20
(3,901 Views)

Just out of curiosity:

 

as seen in the attached picture I moved the release queue VI from the producer loop to the consumer loop. This way I wanted to ensure that the queue is only released if the queue is empty. Now this implementation works according to the tests I have made so far and I don't use notifiers and the error handling is much easier.

 

Are there any drawbacks of my implementation? (Because in Felix's nugget various issues have been mentioned)

 

 

0 Kudos
Message 4 of 20
(3,881 Views)

I don't see how you stop your program. Consumer loop stops on error, which never occures at the moment. How you stop it in the 'No error' case?

 

Felix

0 Kudos
Message 5 of 20
(3,860 Views)

Yes, thanks for the comment! I also noticed it, for some reasons it wasn't obvious as I cared only about the data written into the files.

 

The attached file is the corrected version, it stops the VI.

0 Kudos
Message 6 of 20
(3,850 Views)

What happens if you don't enqueue data in time? If on the first iteration of the consumer you have not yet put any data into the queue it will stop right away. The only reason it doesn't do that is because of the delay caused by the file dialog. I guess if it works then it works. But kind of a scary situation. You might change the code someday and move the TDMS initialize somewhere else and run into issues.

=====================
LabVIEW 2012


Message 7 of 20
(3,843 Views)

Is it possible to overcome this issue without using notifiers? As far as I know the use of notifiers results in a lossy data transfer and unfortunately I must store every data points.

0 Kudos
Message 8 of 20
(3,834 Views)

Just check back to my nugget. Check after the producer if the queue is empty (so the consumer is done) before releasing the queue to terminate the consumer. I think the code is attched there so you just drop it on your BD.

Or send an additional 'command' inside the queue that tells the consumer that the producer is done. If this 'flag' is set, stop the consumer, release the queue.

 

Felix

0 Kudos
Message 9 of 20
(3,826 Views)

I prefer to use distinct messages to stop or exit the consumer loop and perform all cleanup code (releasing queues or notifiers, closing references, etc.) in a separate VI that is called after both the producer and consumer loops have exited. This helps to eliminate the type of race conditions that you are running into.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 10 of 20
(3,821 Views)