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]

[gccgo] Avoid another deadlock in GC when profiling


This patch avoids the other deadlock in GC when profiling: don't let
malloc continue the GC if it is invoked on behalf of the profiler.  The
last patch fixed the case where the GC asked the profiler to start the
GC, this patch fixes the case where the GC asks malloc to start the GC.
Committed to gccgo branch.

Ian

diff -r c4496094f7b1 libgo/runtime/malloc.goc
--- a/libgo/runtime/malloc.goc	Thu Aug 26 15:09:54 2010 -0700
+++ b/libgo/runtime/malloc.goc	Thu Aug 26 15:31:29 2010 -0700
@@ -99,8 +99,16 @@
 
 	__sync_bool_compare_and_swap(&m->mallocing, 1, 0);
 
-	if(__sync_bool_compare_and_swap(&m->gcing, 1, 0))
-		__go_run_goroutine_gc(0);
+	if(__sync_bool_compare_and_swap(&m->gcing, 1, 0)) {
+		if(!(refflag & RefNoProfiling))
+			__go_run_goroutine_gc(0);
+		else {
+			// We are being called from the profiler.  Tell it
+			// to invoke the garbage collector when it is
+			// done.  No need to use a sync function here.
+			m->gcing_for_prof = 1;
+		}
+	}
 
 	if(!(refflag & RefNoProfiling) && (rate = MemProfileRate) > 0) {
 		if(size >= (uint32) rate)

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