You can't try to lock a mutex without having a reference to it. (Since calling mutex->lock will retain a reference in the frame pointer)
I don't remember if there any reasons for why keys don't reference their mutex, except to facilitate garbage collection. It is however vitally important that mutexes do not have references to the keys, and once I had figured out how to do that I probably just applied that symmetrically.
/ Fredrik (Naranek) Hubinette (Real Build Master)
Previous text:
2002-10-27 15:15: Subject: References to Thread.Mutex
It turned out to be caused by the mutex lock object that doesn't hold a reference to the mutex, and the lock is destructed when the mutex is refcount garbed before the call to wait(). (I still don't know what difference is causing the destruct to consistently be sufficiently delayed for me but not for Nilsson.)
Anyway, what is the reason behind the design that MutexKeys doesn't reference their Mutexes? It could potentially cause problems in more relevant cases than this, e.g. during a shutdown sequence if the object containing the mutex is gc'd while there still are several threads that is waiting to get a lock.
/ Martin Stjernholm, Roxen IS