From 8882af17e6ee543c94843b0333c814780d9056d3 Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Tue, 13 Dec 2016 16:53:03 -0500 Subject: [PATCH] [threadpool] Fix `MonoTests.runtime.unload-appdomain-on-shutdown.exe` (#4135) * [threadpool] Increase and decrease refcount when removing domain * [threadpool] Fix unload-appdomain-on-shutdown.exe If the threadpool is not initialized, there is no need to initialize it, as no worker is going to start in the domain because mono_domain_is_unloading would return TRUE. --- mono/metadata/threadpool.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mono/metadata/threadpool.c b/mono/metadata/threadpool.c index ab88e67f4b9..9b404869ea4 100644 --- a/mono/metadata/threadpool.c +++ b/mono/metadata/threadpool.c @@ -607,12 +607,18 @@ mono_threadpool_remove_domain_jobs (MonoDomain *domain, int timeout) * The is_unloading () check in worker_request () ensures that * no new jobs are added after we enter the lock below. */ - mono_lazy_initialize (&status, initialize); + + if (!mono_lazy_is_initialized (&status)) + return TRUE; + + mono_refcount_inc (threadpool); + domains_lock (); tpdomain = tpdomain_get (domain, FALSE); if (!tpdomain) { domains_unlock (); + mono_refcount_dec (threadpool); return TRUE; } @@ -647,6 +653,8 @@ mono_threadpool_remove_domain_jobs (MonoDomain *domain, int timeout) mono_coop_cond_destroy (&tpdomain->cleanup_cond); tpdomain_free (tpdomain); + mono_refcount_dec (threadpool); + return ret; } -- 2.25.1