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;
};