问题描述
我需要对C ++的案例研究提出建议。
I need to suggestion on this case studies on C++.
我采用了多个线程20生产者线程在其上写的队列。将从队列中读取并处理它。
我计划使用关键部分和Semaphore来实现同步。
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 - 在队列中添加消息。
RemoveHead - 从队列中删除数据。
AddTail-Adding message in the Queue.RemoveHead-Remove data from Queue.
我已将队列长度限制为10个。
I have restricted the queue length to 10.
曲线段将保护wrt或/读取问题。
Semaphore将同步访问队列。
Crtical section will protect wrting or/Reading problem.Semaphore will synchronized access to the queue.
让我知道任何其他POssible解决方案。
Let me know any other POssible solution on this.
推荐答案
有很多方法可以编写这样的队列。例如,您可以使用互斥体和条件变量,如我在
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在Dobb博士的文章中讨论了队列。请参见和
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
这篇关于多生产者单消费者问题的信号量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!