I came across a solution to the "Single writer Multiple readers Problem" implemented with Boost here.
I read the Boost manual about Synchronization and some old (2002) article on Dr. Dobb, but I can not figure how this really works.Code: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;
I do know the classics solution to the "Single writer multiple readers" and I guess this is equivalent.
I will be thankful if you could make me get it...



LinkBack URL
About LinkBacks



CornedBee