This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

libgo patch committed: Avoid crash at thread exit


If the garbage collector runs just as a thread is exiting, it can
collect the M structure for the exiting thread.  This can then crash
when locking or unlocking the heap for some final statistics gathering.
This patch fixes that problem.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian

diff -r f68f39af572b libgo/runtime/go-go.c
--- a/libgo/runtime/go-go.c	Fri Jan 21 17:58:59 2011 -0800
+++ b/libgo/runtime/go-go.c	Fri Jan 21 18:09:14 2011 -0800
@@ -297,6 +297,15 @@
 {
   struct M *pm = m;
 
+  if (__sync_bool_compare_and_swap (&pm->holds_finlock, 1, 1))
+    {
+      /* We can't interrupt the thread while it holds the finalizer
+	 lock.  Otherwise we can get into a deadlock when mark calls
+	 runtime_walkfintab.  */
+      __sync_bool_compare_and_swap (&pm->gcing_for_finlock, 0, 1);
+      return;
+    }
+
   if (__sync_bool_compare_and_swap (&pm->mallocing, 1, 1))
     {
       /* m->mallocing was already non-zero.  We can't interrupt the
@@ -315,15 +324,6 @@
       return;
     }
 
-  if (__sync_bool_compare_and_swap (&pm->holds_finlock, 1, 1))
-    {
-      /* Similarly, we can't interrupt the thread while it holds the
-	 finalizer lock.  Otherwise we can get into a deadlock when
-	 mark calls runtime_walkfintab.  */
-      __sync_bool_compare_and_swap (&pm->gcing_for_finlock, 0, 1);
-      return;
-    }
-
   stop_for_gc ();
 }
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]