Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-07-14 14:27:08


"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?

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk