[runtime] Don't return from Monitor.Wait without holding the lock
authorVlad Brezae <brezaevlad@gmail.com>
Tue, 1 Mar 2016 15:46:10 +0000 (17:46 +0200)
committerVlad Brezae <brezaevlad@gmail.com>
Wed, 2 Mar 2016 09:50:04 +0000 (11:50 +0200)
commitb772131cb4d5552bcfc66ea36db3506fab0ed832
treedcf79f054b59b22951d1cb86e536d1621285849b
parent636457dac5b1d7ff340ccb6d827f7a787248bf67
[runtime] Don't return from Monitor.Wait without holding the lock

Even if we are interrupted we must throw the exception only after we have regained the lock. This prevents throwing an SynchronizationLockException in the finally clause of common scenarios like :

lock (obj) {
Monitor.Wait (obj);
}

The downside of this is that, if another thread doesn't give up the lock, we could fail to abort the thread. But this is what MS does.
mono/metadata/monitor.c
mono/tests/Makefile.am
mono/tests/monitor-wait-abort.cs [new file with mode: 0644]