View Single Post
  #2 (permalink)  
Old July 11th, 2017, 04:18 PM
John Mongan John Mongan is offline
Wrox Author
Points: 21, Level: 1
Points: 21, Level: 1 Points: 21, Level: 1 Points: 21, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2012
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Without the while loops, add will silently fail to add the value to the buffer if it is full, and remove will fail to retrieve a valid value from the queue if it is empty.

There are a variety of means that can be used to stop the consumer. One way to do it is called "poison pill": when the producer is ready to shut down it puts a special value on the queue just before it shuts down; when the consumer sees that value it shuts down. To make this work, you have to be sure that the special "poison pill" value is one that would never be placed on the queue in any other context, or you'll have the consumer shutting down when you don't want it to.

John
Reply With Quote