
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.