Help Please:(

I need to answer this question as soon as possible. Please give me your ideas.
Thanks..

question:

The following class is a synchronous circular buffer. It is intended to have a fixed storage size, and it should block the producer thread when full, and the consumer thread when empty.
It makes use of the boost thread library for mutex locking.
Tasks:
• Describe the major problems with this class
• When might you use a class like this.
• Correct the class.
• Show that your solution is correct especially testing boundary conditions.

#pragma once

// This provides uint32_t (although perhaps not on your compiler)
#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;
};
Topic archived. No new replies allowed.