On 10/12/2015 4:17 PM, gast128 wrote:
Knowing whether a mutex is locked is of little use, it does not tell you whether you own a lock on that mutex. Not to mention that the information would already be stale by the time it is returned.
Yes that's what I mean: if the mutex is locked by the calling thread,a although again I didn't specify my self correctly. No race condition possibility out of perspective of the calling thread
could be anything (object instance, scope, function call, underlying thread or execution agent, etc), so the mutex can't tell you that.
Mostly this is done for debugging purposes. Maybe it would a possibility to add some extra information to the mutex. Windows critical section for example keeps track which thread has lock it. This helps tracking down deadlocks in the debugger.
For debugging purposes, you could try creating your own `mutex` wrapper that keeps track of the calling `thread::id`. Note that access to this extra information is potentially concurrent, so you will need to synchronize it internally.
I wasn't the first one who was looking for this: http://stackoverflow.com/questions/21892934/how-to-assert-if-a-stdmutex-is-l...
That looks like an obvious attempt to misuse the existing facilities. Regards, -- Agustín K-ballo Bergé.- http://talesofcpp.fusionfenix.com