|No such thing as a small change|
Re^3: Recursive locks:killer application. Do they have one? (mu)by tye (Sage)
|on Feb 02, 2012 at 23:04 UTC||Need Help??|
What I dislike is the overhead of current implementation with its need to count and no timeout.
I find it hard to imagine how "need to count" can have more than the most trivial of impacts on the efficiency of a mutex.
Ah, Java switching locking schemes explains why this is such a political football, then.
I agree with many of your points above.
IME, the whole idea of needing to retain a lock long enough to call out to another method just seems wrong to me.
True. But the methods I'm talking about were tiny bits of utility code. Think something like "length" or "isReserved".
The only reason the locking would get that complicated for these things was due to being careful to only lock when locking was required. So, a huge fraction of invocations of some method would never even need to lock. When moving the "window" where the lock was held to the smallest possible scopes, those scopes would fairly often move down inside some internal utility method. This was C++ so there was more call for tiny utility methods compared to writing in Perl.
Something like a "move" operation wouldn't have to lock unless either the source or destination was "shared". And a "clear" operation would boil down to a bunch of "move" operations with no outer lock while a "shutdown" operation would lock and then "clear".
But these days I don't program by writing a class and then trying to insert the locks where required so that the class becomes "thread safe". I design the system to not need locks except the minimal number of key places. It is closer to "multiple processes" coding over "multiple threads" coding.
So, instead of some object that might be shared between threads, I'd have a mechanism for transferring responsibilities between threads that would transfer simple data and end up with either two similar, separate objects or one object being destroyed and another created.
So, when I try to put my "multiple threads" programming hat back on, I would want re-entrant mutexes (and requiring an explicit unlock sounds like a really horrid idea). But, stepping back, I'd rather just not go back to that way of thinking and instead do design that can be implemented with "multiple processes" even if the expected implementation is "multiple threads", and that makes "re-entrant or not" mostly a moot question.