Fixes threadpool+ProcessExit problem
authorShay Rojansky <roji@roji.org>
Sun, 18 Nov 2012 20:08:13 +0000 (22:08 +0200)
committerShay Rojansky <roji@roji.org>
Sun, 18 Nov 2012 20:14:00 +0000 (22:14 +0200)
The threadpool was being shutdown too early, before the ProcessExit event was fired.
This led to bugs such as NLog not shutting down
(http://nlog-project.org/2011/10/30/using-nlog-with-mono.html).

mono/metadata/icall.c
mono/metadata/threads.c
mono/mini/mini.c

index e58903aa88ae32ce21eab684712b7c40e4b61aa6..73823823c0ef2d8ac26d00fcc8ed758881d3de8c 100644 (file)
@@ -73,6 +73,7 @@
 #include <mono/metadata/mono-debug.h>
 #include <mono/metadata/mono-ptr-array.h>
 #include <mono/metadata/verify-internals.h>
+#include <mono/metadata/runtime.h>
 #include <mono/io-layer/io-layer.h>
 #include <mono/utils/strtod.h>
 #include <mono/utils/monobitset.h>
@@ -6565,6 +6566,10 @@ ves_icall_System_Environment_Exit (int result)
 {
        MONO_ARCH_SAVE_REGS;
 
+#ifndef MONO_CROSS_COMPILE
+       mono_runtime_shutdown ();
+#endif
+
        mono_threads_set_shutting_down ();
 
        mono_runtime_set_shutting_down ();
index 0b1d72f05b78f371d264a78632054bb0363c6d64..b1376cd2de9493482688980d39de3f7dca1d4590 100644 (file)
@@ -33,6 +33,7 @@
 #include <mono/metadata/monitor.h>
 #include <mono/metadata/gc-internal.h>
 #include <mono/metadata/marshal.h>
+#include <mono/metadata/runtime.h>
 #include <mono/io-layer/io-layer.h>
 #ifndef HOST_WIN32
 #include <mono/io-layer/threads.h>
@@ -2854,6 +2855,10 @@ void mono_thread_manage (void)
                THREAD_DEBUG (g_message ("%s: I have %d threads after waiting.", __func__, wait->num));
        } while(wait->num>0);
 
+#ifndef MONO_CROSS_COMPILE
+       mono_runtime_shutdown ();
+#endif
+
        mono_threads_set_shutting_down ();
 
        /* No new threads will be created after this point */
index f52a44fa2152437471def187b4888fc2e146dcdc..5f035d7e4ef6b39d36069617e995d97219ad9a62 100644 (file)
@@ -6863,12 +6863,9 @@ mini_cleanup (MonoDomain *domain)
 #endif
 
 #ifndef MONO_CROSS_COMPILE     
-       mono_runtime_shutdown ();
        /* 
-        * mono_runtime_cleanup() and mono_domain_finalize () need to
-        * be called early since they need the execution engine still
-        * fully working (mono_domain_finalize may invoke managed finalizers
-        * and mono_runtime_cleanup will wait for other threads to finish).
+        * mono_domain_finalize () needs to be called early since it needs the
+        * execution engine still fully working (it may invoke managed finalizers).
         */
        mono_domain_finalize (domain, 2000);
 #endif