[threads] Always use the `suspended` MonoOSEvent for self-suspend (#3915)
authorLudovic Henry <ludovic@xamarin.com>
Wed, 9 Nov 2016 20:59:36 +0000 (15:59 -0500)
committerGitHub <noreply@github.com>
Wed, 9 Nov 2016 20:59:36 +0000 (15:59 -0500)
commit38a348c991049fb0134e27774292c2d8929fda22
tree63f5490bf98d588c1718aab3ad046980dc14addf
parent723e5a1b07db0f4d83c01bf41e8e6120ea86b3b5
[threads] Always use the `suspended` MonoOSEvent for self-suspend (#3915)

* [stw] Refactor to treat error/success cases first

* [threads] Always use the `suspended` MonoOSEvent for self-suspend

The previous self-suspend mechanism was inherently racy:
 - T1 self suspend:
  - T1 calls mono_thread_info_begin_self_suspend, but doesn't call mono_thread_info_end_self_suspend yet
 - T2 suspends T1 <-- the suspend_count is > 0, trigerring the assertion at mono-threads.c:184
mcs/class/corlib/System.Threading/Thread.cs
mcs/class/corlib/System/Environment.cs
mono/metadata/appdomain.c
mono/metadata/object-internals.h
mono/metadata/sgen-stw.c
mono/metadata/threads.c
mono/tests/Makefile.am
mono/tests/thread-suspend-selfsuspended.cs [new file with mode: 0644]
mono/utils/mono-threads-state-machine.c
mono/utils/mono-threads.c
mono/utils/mono-threads.h