This was from compsci lecture quiz that my professor want us to challenge. he said that this class is about circular buffer but has got major problem. I've try to think for whole day but have no clue. please give me some ideas
#include <stdint.h>
#include <boost/thread.hpp>
template <typename T, uint32_t max>
class CircularBuffer
{
public:
CircularBuffer() : m_WriteOffset(0), m_ReadOffset(0){}
~CircularBuffer(){};
void push( T val )
{
boost::lock_guard<boost::mutex> guard( m_Mutex );
m_Buffer[m_WriteOffset++] = val;
}
T pull()
{
boost::lock_guard<boost::mutex> guard( m_Mutex );
return m_Buffer[m_ReadOffset++];
}
private:
boost::mutex m_Mutex;
enum { MAX_SIZE = max };
T m_Buffer[MAX_SIZE];
uint32_t m_WriteOffset;
uint32_t m_ReadOffset;
};