Mutexes and locking

Jeremy DeHaan dehaan.jeremiah at gmail.com
Wed Mar 5 09:49:04 PST 2014


On Monday, 3 March 2014 at 07:38:05 UTC, Ali Çehreli wrote:
> The documentation says that Mutex is a recursive lock, meaning 
> that the holder of the lock can lock it even further. :) There 
> is an internal reference count so that the lock must be 
> unlocked the equal number of times that it has been locked.



Maybe this is because I haven't done much work with 
multi-threading, but this seems like a strange thing. What would 
be the benefits of locking a mutex more than once? It makes sense 
to me that a mutex should be allowed to be locked only once, and 
anything else trying to lock it get's held up until it has been 
unlocked, or a false is returned in the case of a tryLock.

and this may seem like a silly question(like I said, not much 
multi-threading experience), but what determines the holder of a 
lock? Is it the thread or is it a specific function? Or something 
else?


More information about the Digitalmars-d-learn mailing list