
14 Jul
2004
14 Jul
'04
7:27 p.m.
"Peter Dimov" <pdimov@mmltd.net> 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