Boost logo

Boost :

From: Howard Hinnant (hinnant_at_[hidden])
Date: 2004-07-09 13:46:31

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);
     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)?


Boost list run by bdawes at, gregod at, cpdaniel at, john at