From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-07-09 17:05:03
Howard Hinnant wrote:
> On Jul 9, 2004, at 4:11 PM, Peter Dimov wrote:
>>> rw_mutex m;
>>> void invitation_for_deadlock()
>>> read_lock r(m);
>>> // ok to read
>>> upgradable_read_lock ur(m);
>>> 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
>> Not scary, IMO, even if not obvious, because it always deadlocks, as
>> soon as you attempt the "idiom". You can't miss it.
> I'm not following "always deadlocks". If only one thread enters, at
> what point does it deadlock (assuming no other thread playing with m)?
> Experimentally running through this on my prototype implementation with
> a single thread isn't deadlocking. But perhaps my prototype is buggy?
I wouldn't bet on that. Can I change my opinion to "scary"? ;-)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk