Confused about shared_mutex usage.

Hi all, I'm looking at the shared_mutex documentation here: http://www.boost.org/doc/libs/1_35_0/doc/html/thread/synchronization.html#th... But the documentation seems to be a little bit sparse and I'm having trouble figuring out how to use shared_mutex as a read/write lock. Just to make sure, lock_shared/unlock_shared is for the "readers", and lock/unlock is for the "writers"? If not, how do I lock/unlock it for reading, and how do I lock/unlock it for writing (exclusive lock)? Also I'm having trouble understanding what a "lock" is as opposed to a mutex. What is boost::shared_lock? Thanks! Jason

On Thu, Jul 2, 2009 at 6:40 AM, Jason Cipriani
I'm looking at the shared_mutex documentation here:
http://www.boost.org/doc/libs/1_35_0/doc/html/thread/synchronization.html#th...
But the documentation seems to be a little bit sparse and I'm having trouble figuring out how to use shared_mutex as a read/write lock. Just to make sure, lock_shared/unlock_shared is for the "readers", and lock/unlock is for the "writers"? If not, how do I lock/unlock it for reading, and how do I lock/unlock it for writing (exclusive lock)?
Also I'm having trouble understanding what a "lock" is as opposed to a mutex. What is boost::shared_lock?
I think I've got it all figured out, nevermind. Lock/unlock is for write (exclusive) locks, shared_lock/shared_unlock is for read locks, and then boost::unique_lock and boost::shared_lock are scoped locking and unlocking wrappers. Thanks, Jason

AMDG Jason Cipriani wrote:
Hi all,
I'm looking at the shared_mutex documentation here:
http://www.boost.org/doc/libs/1_35_0/doc/html/thread/synchronization.html#th...
But the documentation seems to be a little bit sparse and I'm having trouble figuring out how to use shared_mutex as a read/write lock. Just to make sure, lock_shared/unlock_shared is for the "readers", and lock/unlock is for the "writers"? If not, how do I lock/unlock it for reading, and how do I lock/unlock it for writing (exclusive lock)?
Also I'm having trouble understanding what a "lock" is as opposed to a mutex. What is boost::shared_lock?
A lock is an RAII class. { // acquire lock boost::shared_lockboost::shared_mutex l(m_mutex); // do stuff } // lock released { // acquire lock boost::unique_lockboost::shared_mutex l(m_mutex); // do stuff } // lock released In Christ, Steven Watanabe
participants (2)
-
Jason Cipriani
-
Steven Watanabe