Make threadpool_clear_queue resistant to concurrent runtime shutdown.
authorRodrigo Kumpera <kumpera@gmail.com>
Thu, 6 Jun 2013 22:42:40 +0000 (18:42 -0400)
committerRodrigo Kumpera <kumpera@gmail.com>
Thu, 6 Jun 2013 23:00:06 +0000 (19:00 -0400)
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

index 09c5c9a9b5b63534ea76d48af4264ab619eecfad..78c8121c8cffdb32dd9299584933d8fe382ad414 100644 (file)
@@ -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);