From 1ab5169f9ca0f399c3cd55b266fee33e0657bd8e Mon Sep 17 00:00:00 2001 From: Rodrigo Kumpera Date: Thu, 6 Jun 2013 18:42:40 -0400 Subject: [PATCH] Make threadpool_clear_queue resistant to concurrent runtime shutdown. If threadpool_clear_queue is called while the runtime is been shutdown it might crash since the queue will have been cleaned. So now we guard against null queues and bail out from appending the existing jobs if shutdown was initiated. --- mono/metadata/threadpool.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mono/metadata/threadpool.c b/mono/metadata/threadpool.c index 09c5c9a9b5b..78c8121c8cf 100644 --- a/mono/metadata/threadpool.c +++ b/mono/metadata/threadpool.c @@ -1095,10 +1095,13 @@ static void threadpool_clear_queue (ThreadPool *tp, MonoDomain *domain) { MonoObject *obj; - MonoMList *other; + MonoMList *other = NULL; + MonoCQ *queue = tp->queue; - other = NULL; - while (mono_cq_dequeue (tp->queue, &obj)) { + if (!queue) + return; + + while (mono_cq_dequeue (queue, &obj)) { if (obj == NULL) continue; if (obj->vtable->domain != domain) @@ -1106,6 +1109,9 @@ threadpool_clear_queue (ThreadPool *tp, MonoDomain *domain) threadpool_jobs_dec (obj); } + if (mono_runtime_is_shutting_down ()) + return; + while (other) { threadpool_append_job (tp, (MonoObject *) mono_mlist_get_data (other)); other = mono_mlist_next (other); -- 2.11.4.GIT