335 Subj : Re: many producers/one consumer To : comp.programming.threads From : Eric Sosman Date : Thu Feb 17 2005 11:21 am Keith O wrote: > Hi, > > I have a many producers(threads) that add data to a queue and one > consumer(thread) that reads from the queue and writes the data to a > database. > > What is a good algorithm to handle this sort of thing. The thing that's > bugging me is when the producers finish producing data and exit, I want the > consumer to know that it should stop checking for new data and exit. One approach is for each producer to put a final "Hail and farewell" item on the end of the queue just before it exits. When the consumer finds this special item it can decrement its N_producers counter and exit if it's reached zero. -- Eric.Sosman@sun.com . 0