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"
if (mono_thread_cleanup_fn)
mono_thread_cleanup_fn (thread_get_tid (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;
if (mono_gc_is_moving ()) {
MONO_GC_UNREGISTER_ROOT (thread->thread_pinning_ref);
thread->thread_pinning_ref = NULL;