From: Ludovic Henry Date: Fri, 16 Dec 2016 18:42:36 +0000 (-0500) Subject: [threads] Ensure thread is still alive when detaching it X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=mono.git;a=commitdiff_plain;h=f4fdfcc714328cba1379f25590aa51128c558743 [threads] Ensure thread is still alive when detaching it 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" --- diff --git a/mono/metadata/threads.c b/mono/metadata/threads.c index d874b5664c7..fd424bdfb90 100644 --- a/mono/metadata/threads.c +++ b/mono/metadata/threads.c @@ -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;