Boost logo

Boost :

From: Bronek Kozicki (brok_at_[hidden])
Date: 2004-08-04 15:45:26


Is there any reason for distinction between shared lock and upgradable
shared lock? I mean - obviously updgradable shared lock can be upgraded
to exclusive one, but do we need separate type for this? What's
rationale behind this distinciton? I can easily imagine design (and
implementation) where every shared lock is also upgradable one, if it's
mutex type support upgrade operation. Under such design one can upgrade
shared lock only if it's the only (currently locking) lock on
synchromization object (supporting such transition). Implementation of
such mutex could be very similar to semaphore (or just using semaphore,
if present on platform).

Here are some simple use cases:

some_mutex_type_not_supporting_shared_locks m1;
shared_lock<some...> l1(m1); // compilation error

some_mutex_type_fully_supporting_shared_locks m2;
shared_lock<some...> l2(m2); // ok
exclusive_lock<some...> l3 = l2.try_upgrade(); // ok, non-blocking

some_mutex_type_with_limited_support_for_shared_locks m3;
shared_lock<some...> l4(m3); // ok
exclusive_lock<some...> l5 = l4.try_upgrade(); // compilation error
exclusive_lock<some...> l6 = l4.upgrade(); // ok, blocking

some_mutex_type_with_minimal_support_for_shared_locks m4;
{
   shared_lock<some...> l7(m4); // ok
   exclusive_lock<some...> l8 = l7.try_upgrade(); // compilation error
   exclusive_lock<some...> l9 = l7.upgrade(); // compilation error
}
exclusive_lock<some...> l10(m4); // ok

B.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk