[Mono-devel-list] Monitor_exit from same thread required?

Michi Henning michi at zeroc.com
Thu Feb 26 20:14:31 EST 2004

Joshua Perry wrote:

> If(mon->owner!=GetCurrentThreadId ()) {
>             mono_raise_exception(mono_get_exception_synchronization_lock 
> (“Not locked by this thread”));
>             return;
> }
> My question is:  Is this necessary?  And if so, why don’t I have a 
> problem with it in windows?

Windows is probably less thorough in its error checking. However,
it is illegal for a thread to unlock a monitor unless it currently
holds the lock on that monitor. Doing so has undefined behavior,
which is what you are seeing under Windows. (It just so happens
that "undefined behavior" in the Windows case just means "it
happens to work.")



More information about the Mono-devel-list mailing list