|
Boost Users : |
From: Selçuk Giray Özdamar (selcukgiray_at_[hidden])
Date: 2008-05-20 12:14:53
Hi everyone, can anyone send a simple container class implementation, which
supports concurrent reads and exclusive write. I'm seeking for the usage of
shared_lock for read/write mutex. My simple template class snippet is shown
below, please reply how to fill the comments for locking. Thnx.
// std includes
#include <vector>
// boost includes
#include <boost/thread/shared_mutex.hpp>
template <typename T>
class SharedContainer
{
public:
SharedContainer (void){}
~SharedContainer (void){}
void push_back(const T& value);
const T& at(int index) const;
private:
std::vector<T> m_buffer;
boost::shared_mutex rw_mutex; //is this the correct class for rw
mutex?
};
template <typename T>
void EntityUpdateBuffer<T>::push_back( const T& value )
{
// how to acquire a write lock?
m_buffer.push_back(value);
}
template <typename T>
const T& EntityUpdateBuffer<T>::at( int index ) const
{
// how to acquire read lock?
return m_buffer.at(index);
}
Selcuk Giray
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net