|
Boost : |
From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2004-11-03 16:47:45
Michael Glassford wrote:
[...]
> lock lock1(m);
>
> //...
>
> lock lock2(m); //Recursive lock
>
> while (!b)
> c.wait(lock2); //***
[...]
> deadlock results.
POSIX threads philosophy is that (quoting DRB) "when a thread does
call another routine while holding a mutex, (with the exception of
unlock and wait!) the called code MUST assume that the mutex is
locked because one or more program invariants are broken. That's
WHY you lock mutexes, and when the invarient is no longer broken,
you should UNLOCK them. ... If you "spin out" the recursive lock
to free it, you are breaking the calling code by exposing the
supposedly protected (broken) invariants to other threads,
unprepared to handle this." So deadlock isn't that bad. ;-)
See also:
http://lists.boost.org/MailArchives/boost/msg67187.php
regards,
alexander.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk