|
Boost Users : |
Subject: Re: [Boost-users] [Thread] Read-write locks
From: Brian Budge (brian.budge_at_[hidden])
Date: 2011-01-27 17:53:31
On Thu, Jan 27, 2011 at 2:37 PM, <lfrfly_at_[hidden]> wrote:
> I'm trying to create a standard read/write lock using Boost Threads, and I'm
> having a bit of difficulty mapping the Boost concepts onto the usual ones.
>
> A read/write lock should have several states: Locked for reading (multiple
> threads may lock at once), locked for writing (only one thread may lock, and
> no threads may be locked for reading at the same time), and unlocked.
> Ideally it would be nice if an RWL which is locked for reading may
> temporarily upgrade to locked for writing, then return to the locked for
> reading state.
>
> Boost supports several relevant notions of locking: shared locking, upgrade
> locking, and exclusive locking. This to me is a confusing distinction. In
> particular, a shared_mutex seems appropriate as the basis for a RWL, but is
> lock_upgrade() the equivalent of a write lock and lock_shared the equivalent
> of a read lock? This is unclear. If "upgrade locking" is not the same as
> "exclusive locking", then is an upgrade lock actually exclusive? Could
> someone please clarify this.
Hi -
So you want to use a shared_mutex, and for reading you use a
shared_lock, for writing you use a unique_lock, and then if you have a
read lock and want to upgrade, you upgrade from a shared to unique
lock.
Hope that helps,
Brian
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net