In mono_thread_info_suspend_lock in non-coop, don't assert MonoThreadInfo* is non...
authorAleksey Kliger <aleksey@xamarin.com>
Thu, 15 Jun 2017 17:50:10 +0000 (13:50 -0400)
committerAleksey Kliger <aleksey@xamarin.com>
Thu, 15 Jun 2017 17:50:10 +0000 (13:50 -0400)
mono_thread_info_suspend_lock () can be called from boehm-gc.c
on_gc_notification before the new thread's start_wrapper calls
mono_thread_info_attach but after pthread_create calls the start wrapper.

As a result, the asserts in mono_thread_info_suspend_lock_with_info can catch
the new thread in an inconsistent state.

mono/utils/mono-threads.c

index dac28b7037dbe4f739cfa543457f1d8514305c14..6afb74daf8de35618dbe6a1374f9100aaf64c124 100644 (file)
@@ -1029,16 +1029,21 @@ STW to make sure no unsafe pending suspend is in progress.
 static void
 mono_thread_info_suspend_lock_with_info (MonoThreadInfo *info)
 {
-       g_assert (info);
-       g_assert (mono_thread_info_is_current (info));
-       g_assert (mono_thread_info_is_live (info));
+       if (mono_threads_is_coop_enabled ()) {
+               g_assert (info);
+               g_assert (mono_thread_info_is_current (info));
+               g_assert (mono_thread_info_is_live (info));
 
-       MONO_ENTER_GC_SAFE_WITH_INFO(info);
+               MONO_ENTER_GC_SAFE_WITH_INFO(info);
 
-       int res = mono_os_sem_wait (&global_suspend_semaphore, MONO_SEM_FLAGS_NONE);
-       g_assert (res != -1);
+               int res = mono_os_sem_wait (&global_suspend_semaphore, MONO_SEM_FLAGS_NONE);
+               g_assert (res != -1);
 
-       MONO_EXIT_GC_SAFE_WITH_INFO;
+               MONO_EXIT_GC_SAFE_WITH_INFO;
+       } else {
+               int res = mono_os_sem_wait (&global_suspend_semaphore, MONO_SEM_FLAGS_NONE);
+               g_assert (res != -1);
+       }
 }
 
 void