[runtime] Fix #26307 "Random crash due to threading issue in new threadpool heuristic...
authorLudovic Henry <ludovic.henry@xamarin.com>
Wed, 28 Jan 2015 20:10:37 +0000 (15:10 -0500)
committerLudovic Henry <ludovic.henry@xamarin.com>
Wed, 28 Jan 2015 20:56:07 +0000 (15:56 -0500)
By locking `threads_lock` before launching the thread, we guarantee that the thread is not going to remove itself from `threads` before we actually add it to `threads`.

mono/metadata/threadpool.c

index 36514cc6ea8a06c0f26c553ecb68e59de2d846a7..27ba80ecd62cf693d7e530ab5aea827cfb4b537c 100644 (file)
@@ -1195,9 +1195,11 @@ threadpool_start_thread (ThreadPool *tp)
 #ifndef DISABLE_PERFCOUNTERS
                        mono_perfcounter_update_value (tp->pc_nthreads, TRUE, 1);
 #endif
-                       thread = mono_thread_create_internal (mono_get_root_domain (), tp->async_invoke, tp, TRUE, stack_size);
-                       if (!tp->is_io) {
+                       if (tp->is_io) {
+                               thread = mono_thread_create_internal (mono_get_root_domain (), tp->async_invoke, tp, TRUE, stack_size);
+                       } else {
                                mono_mutex_lock (&threads_lock);
+                               thread = mono_thread_create_internal (mono_get_root_domain (), tp->async_invoke, tp, TRUE, stack_size);
                                g_assert (threads != NULL);
                                g_ptr_array_add (threads, thread);
                                mono_mutex_unlock (&threads_lock);