[Boost-users] Reader/Writer Mutex

118 views
Skip to first unread message

Selçuk Giray Özdamar

unread,
Jun 5, 2008, 9:10:43 AM6/5/08
to boost...@lists.boost.org
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;
};

Anthony Williams

unread,
Jun 5, 2008, 9:24:15 AM6/5/08
to boost...@lists.boost.org
"Selçuk Giray Özdamar" <selcu...@gmail.com> writes:

> 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?

It looks fine to me.

Anthony
--
Anthony Williams | Just Software Solutions Ltd
Custom Software Development | http://www.justsoftwaresolutions.co.uk
Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL

_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Reply all
Reply to author
Forward
0 new messages