How to implement this scenario using thread
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Gang_Zhao
Posted On:   Thursday, June 7, 2001 09:44 PM

I want to implement this scenario: there is one product pooling, one producer and one comsumer.
The producer can produce the product ceaselessly and add the product to the end of the pooling queue.The comsumer can get the first product from queue and repeatly.If there is no product in queue,the consumer is waiting.When the producer put the product into the queue, if the queue is empty,it can notify the comsumer to get. In my opnion, if the comsumer is getting the product, the producer can put the product.
How can I implement such scenario?

Re: How to implement this scenario using thread

Posted By:   Alex_Chaffee  
Posted On:   Sunday, June 17, 2001 06:14 PM


You just described a blocking queue. Search this FAQ for more information.


(See the little box labeled "Search" in the upper-right corner? That's for searching. For instance, I type in "producer consumer" and I get three hits, one of which contains full source code for solving your problem.)


By the way, if this is trolling for the answer for a final exam, I'll be very disappointed... :-)

About | Sitemap | Contact