Avoid a deadlock when waiting for pending finalizers.
authorRodrigo Kumpera <kumpera@gmail.com>
Fri, 18 May 2012 20:06:32 +0000 (17:06 -0300)
committerRodrigo Kumpera <kumpera@gmail.com>
Fri, 18 May 2012 20:10:35 +0000 (17:10 -0300)
* gc.c: If the finalizer thread is delay started
we must ensure that we don't block waiting for finalizers
until it is live.

This is required as the delayed start could happen in
the blocked thread - and deadlock us.

mono/metadata/gc.c

index 723bacf93a215982f8156ef10c263aeec7b5cef6..ce1afbe1473d4931c745bb8a800ec04718a045e6 100644 (file)
@@ -485,6 +485,13 @@ ves_icall_System_GC_WaitForPendingFinalizers (void)
                /* Avoid deadlocks */
                return;
 
+       /*
+       If the finalizer thread is not live, lets pretend no finalizers are pending since the current thread might
+       be the one responsible for starting it up.
+       */
+       if (gc_thread == NULL)
+               return;
+
        ResetEvent (pending_done_event);
        mono_gc_finalize_notify ();
        /* g_print ("Waiting for pending finalizers....\n"); */