Subj : Re: recursive mutexes To : comp.programming.threads From : Uenal Mutlu Date : Sat May 21 2005 12:15 am "David Schwartz" wrote > > "Uenal Mutlu" wrote in message > > >> As I said, assuming it's the last unlock. > > > Wake not necessary at all (at least in my implementations of both > > recursive and non-recursive mutex methods). > > You can always trade-off expenses in one place by moving them to > someplace else. That's why I don't make the argument that recursive mutexes > are bad because they're more expensive than non-recursive mutexes. > > They are in fact more expensive in every implementation I've ever seen > that didn't just deliberately impose the expense on non-recursive mutexes as > well. You can't avoid the fact that an 'Unlock' has to determine whether or > not it's actually going to release the mutex as an additional expense not > present in a non-recursive mutex. You can only remove that expense by making > 'Lock' much more expensive so that it can handle the case where it failed to > get the lock but still blocked other threads. > > If you think I'm wrong, prove it. Present an implementation of a > recursive mutex such that it can't be made significantly less expensive by > making it non-recursive. I'll even ignore the overhead of the extra > locks/unlocks, I'm only concerned with the cost of the first lock and the > first unlock. If you can do it, I will call you a genius. > > That said, it really doesn't matter. The problem with recursive mutexes > is not that they hurt performance, because that's generally negligible. It's > that they hide serious design flaws and promote sloppy design. Their *only* > use is to allow you to write code that manipulates an object without knowing > whether or not it holds a lock on that object. And that is just bad, bad, > bad. IMO, this all has nothing to do with what you are replying to. And besides this, we already had "cleared" all these things above by simply finding not a consensus, rather each continued believing in his own view. Ie. I prefer the intelligent use of recursive mutex to simplify and ease the development, whereas most who participated in these discussions stated that they find the use of recursive mutexes a bad idea and that they prefer to use non-recursive mutex only (if that's only true for a really complex system...) And, I can imagine people who develop for Windows and do use CriticalSection that they probably aren't aware of the fact that they actually are using a recursive mutex. .