Subj : Re: many producers/one consumer To : comp.programming.threads From : Lankad Date : Thu Feb 17 2005 01:57 pm that's a cool idea, maybe I'll try this in another program... I already implemented the counter method... Thanks "Eric Sosman" wrote in message news:cv2ga6$g9d$1@news1brm.Central.Sun.COM... > > > 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 > .