[threadpool-ms] Remove thread waiting and memory cleanup
authorLudovic Henry <ludovic.henry@xamarin.com>
Mon, 11 May 2015 12:37:25 +0000 (13:37 +0100)
committerLudovic Henry <ludovic.henry@xamarin.com>
Mon, 11 May 2015 12:37:25 +0000 (13:37 +0100)
This could lead to hangs because threadpool->counter._.active would not be decremented. It means we cannot cleanup memory as the threads may still try to access the threadpool global variable.

mono/metadata/threadpool-ms.c

index 3b8229414d0a329a2166791802376ae647492c7a..fba30d4d9da62b7266ffc1cf95a0cedd283901df 100644 (file)
@@ -359,41 +359,6 @@ ensure_cleanedup (void)
 
        mono_mutex_unlock (&threadpool->active_threads_lock);
 
-       for (;;) {
-               ThreadPoolCounter counter = COUNTER_READ ();
-               if (counter._.active == 0)
-                       break;
-               if (counter._.active == 1) {
-                       MonoInternalThread *thread = mono_thread_internal_current ();
-                       if (thread->threadpool_thread) {
-                               /* if there is only one active thread
-                                * left and it's the current one */
-                               break;
-                       }
-               }
-
-               usleep (1000);
-       }
-
-       g_ptr_array_free (threadpool->domains, TRUE);
-       mono_mutex_destroy (&threadpool->domains_lock);
-
-       g_ptr_array_free (threadpool->parked_threads, TRUE);
-       g_ptr_array_free (threadpool->working_threads, TRUE);
-       mono_mutex_destroy (&threadpool->active_threads_lock);
-
-       mono_mutex_destroy (&threadpool->heuristic_lock);
-       g_free (threadpool->heuristic_hill_climbing.samples);
-       g_free (threadpool->heuristic_hill_climbing.thread_counts);
-       rand_free (threadpool->heuristic_hill_climbing.random_interval_generator);
-
-       g_free (threadpool->cpu_usage_state);
-
-       g_assert (threadpool);
-       g_free (threadpool);
-       threadpool = NULL;
-       g_assert (!threadpool);
-
        status = STATUS_CLEANED_UP;
 }