Boost logo

Boost Users :

From: Selçuk Giray Özdamar (selcukgiray_at_[hidden])
Date: 2008-06-05 09:10:43


Hi everyone,
Below you can see my simple thread safe class which allows multiple readers
and exclusive write for single writer. Is this boost implementation correct?

Also if anyone has other aspects, I'm open.
Regards...

typedef boost::shared_mutex ReadWriteMutex;
typedef boost::shared_lock<boost::shared_mutex> ReadLock;
typedef boost::unique_lock<boost::shared_mutex> WriteLock;

class MtClass
{
public:
 MtClass()
  : m_value()
 {
 }
 ~MtClass(){}

 void setValue(int value)
 {
  WriteLock w_lock(rw_mutex);
  m_value = value;
 }

 int getValue(void) const
 {
  ReadLock r_lock(rw_mutex);
  return m_value;
 }

private:
 int m_value;
 mutable ReadWriteMutex rw_mutex;
};



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