C++ Templated Producer-Consumer BlockingQueue, unbounded buffer: How do I end elegantly?
问题 I wrote a BlockingQueue in order to communicate two threads. You could say it follows the Producer-Consumer pattern, with an unbounded buffer. Therefore, I implemented it using a Critical Section and a Semaphore, like this: #pragma once #include "Semaphore.h" #include "Guard.h" #include <queue> namespace DRA{ namespace CommonCpp{ template<class Element> class BlockingQueue{ CCriticalSection m_csQueue; CSemaphore m_semElementCount; std::queue<Element> m_Queue; //Forbid copy and assignment