Vikram Ranabhatt
Vikram Ranabhatt

Reputation: 7620

Semaphore On Multiple Producer Single Consumer Problem

I need to suggestion on this case studies on C++.

I have taken Queue where multiple Thread 20 Producer thread is writing on it.there is single Consumer thread which will Read from the queue and process it. I am planning to use critical section and Semaphore to achieve synchronization.

AddTail-Adding message in the Queue. RemoveHead-Remove data from Queue.

I have restricted the queue length to 10.

Crtical section will protect wrting or/Reading problem. Semaphore will synchronized access to the queue.

Let me know any other POssible solution on this.

Upvotes: 0

Views: 3448

Answers (1)

Anthony Williams
Anthony Williams

Reputation: 68591

There are many ways to write such a queue. For example, you could use a mutex and a condition variable as in my example at http://www.justsoftwaresolutions.co.uk/threading/implementing-a-thread-safe-queue-using-condition-variables.html

Herb Sutter discusses queues in his articles at Dr Dobb's. See http://www.drdobbs.com/high-performance-computing/211601363 and http://www.drdobbs.com/high-performance-computing/210604448

Upvotes: 5

Related Questions