Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-07-09 15:11:03


Howard Hinnant wrote:
> If we continue with the upgradable_read_lock idea, I see one danger
> that needs to be clearly documented.
>
> Some "genius" is going to figure out that you can atomically convert a
> read_lock into a write_lock:
>
> rw_mutex m;
>
> void invitation_for_deadlock()
> {
> read_lock r(m);
> // ok to read
> upgradable_read_lock ur(m);
> r.unlock();
> write_lock w(ur);
> // ok to write
> }
>
> And the next thing we'll know is that the entire NE US is falling into
> a blackout. ;-)
>
> It took me awhile to spot the deadlock in the above code. Does anyone
> else see the above code as scary? (scary as in looks ok but isn't).
> Or is the deadlock obvious to everyone else (and thus not scary)?

Not scary, IMO, even if not obvious, because it always deadlocks, as soon as
you attempt the "idiom". You can't miss it.


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