Implementing lock/unlock with boost::thread
I'm trying to implement a class having a lock and an unlock-method. If several different threads call scoped_lock::lock, what is the effect? class AntiRAII{ public: AntiRAII() : mLock(mMutex, false) {} void Lock() {mLock.lock(); } void Unlock() {mLock.unlock();} private: boost::mutex mMutex; boost::mutex::scoped_lock mLock; }; I cannot find any documentation on the behaviour. The usual usage of scoped_lock is one per thread, which is why I'm sceptical to this approach. How can this be implemented? Is it better to expose the mutex? Regards, Johan Torp
Johan Torp wrote:
I'm trying to implement a class having a lock and an unlock-method.
Why?
How can this be implemented? Is it better to expose the mutex?
The mutex should be accessible by the functions that manipulate the data it is supposed to protect, but not by other functions. Ben.
participants (3)
-
Ben Hutchings
-
Johan Torp
-
Peter Dimov