[threads] Ensure thread is still alive when detaching it
authorLudovic Henry <ludovic@xamarin.com>
Fri, 16 Dec 2016 18:42:36 +0000 (13:42 -0500)
committerLudovic Henry <ludovic@xamarin.com>
Fri, 16 Dec 2016 18:42:38 +0000 (13:42 -0500)
If the compiler optimized it so that we would unregister the thread->thread_pinning_ref GC root before we would destroy the thread fields, we could run into "* Assertion at threads.c:1081, condition 'thread->suspended' not met"

mono/metadata/threads.c

index d874b5664c753ac83209ae3d8b9f7f46ccdfa8a0..fd424bdfb90ca00d66a27b7c722c9f3dda8eee3d 100644 (file)
@@ -1086,6 +1086,8 @@ mono_thread_detach_internal (MonoInternalThread *thread)
        if (mono_thread_cleanup_fn)
                mono_thread_cleanup_fn (thread_get_tid (thread));
 
+       mono_memory_barrier ();
+
        if (mono_gc_is_moving ()) {
                MONO_GC_UNREGISTER_ROOT (thread->thread_pinning_ref);
                thread->thread_pinning_ref = NULL;