From: Ludovic Henry Date: Fri, 8 Sep 2017 18:07:00 +0000 (-0400) Subject: [threads] Fix "[threads] Fix leaking threads: SGen Worker and Finalizer (#5284)"... X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=mono.git;a=commitdiff_plain;h=d96de323da8d7d9561ecbb5c2ebcdeb23ee1ee2e [threads] Fix "[threads] Fix leaking threads: SGen Worker and Finalizer (#5284)" (#5532) * Revert "[threads] Fix leaking threads: SGen Worker and Finalizer (#5284)" The sgen-specific cleanup cannot be run before the sgen-agnostic cleanup This reverts commit 7db0fb0c886f5157066e26c2e2ae2d39c338cf6b. * [threads] Make sure we do not leak the finalizer and sgen threadpool threads --- diff --git a/mono/metadata/gc.c b/mono/metadata/gc.c index 28b4747b27e..3c78b6153c2 100644 --- a/mono/metadata/gc.c +++ b/mono/metadata/gc.c @@ -973,11 +973,6 @@ mono_gc_cleanup (void) return; if (!gc_disabled) { - - /* Stop all worker threads before signalling the finalizer to stop - * That way the finalizer has a chance to clean up the worker threads */ - mono_gc_base_cleanup (); - finished = TRUE; if (mono_thread_internal_current () != gc_thread) { int ret; @@ -1000,8 +995,7 @@ mono_gc_cleanup (void) ret = guarded_wait (gc_thread->handle, MONO_INFINITE_WAIT, FALSE); g_assert (ret == MONO_THREAD_INFO_WAIT_RET_SUCCESS_0); - /* Clean up the finalizer (and other threads that might still wait to be joined) */ - mono_threads_join_threads (); + mono_threads_add_joinable_thread (GUINT_TO_POINTER (gc_thread->tid)); break; } @@ -1026,8 +1020,7 @@ mono_gc_cleanup (void) g_assert (ret == MONO_THREAD_INFO_WAIT_RET_SUCCESS_0); - /* Clean up the finalizer (and other threads that might still wait to be joined) */ - mono_threads_join_threads (); + mono_threads_add_joinable_thread (GUINT_TO_POINTER (gc_thread->tid)); break; } @@ -1038,6 +1031,7 @@ mono_gc_cleanup (void) } } gc_thread = NULL; + mono_gc_base_cleanup (); } mono_reference_queue_cleanup (); diff --git a/mono/metadata/threads.c b/mono/metadata/threads.c index 61e4531a3c7..c97f7f3f53c 100644 --- a/mono/metadata/threads.c +++ b/mono/metadata/threads.c @@ -3037,6 +3037,8 @@ mono_thread_callbacks_init (void) void mono_thread_cleanup (void) { + mono_threads_join_threads (); + #if !defined(RUN_IN_SUBTHREAD) && !defined(HOST_WIN32) /* The main thread must abandon any held mutexes (particularly * important for named mutexes as they are shared across