Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-07-15 07:49:07

David Abrahams wrote:
> "Peter Dimov" <pdimov_at_[hidden]> writes:
>> I have a recursive_mutex use case that's not as trivial, though.
>> Imagine a mutex pool with a fixed size N that protects an unbounded
>> set of objects (hashing the object address mod N to determine the
>> mutex to lock). Now when you need to protect two objects at the same
>> time, due to the probability of a collision the mutexes need to be
>> recursive. It's still not watertight, because if the two locks are
>> removed from each other, this seems like a deadlock invitation; and
>> if the two locks are made at the same time, the recursive lock can
>> be avoided locally.
> Can't you just check the hashes and only lock once in that case?

You can, if the two locks are made at the same time, but not if one is
"deeper" in the call hierarchy.

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