From: Dmitriy Vyukov Date: Tue, 16 Oct 2012 10:41:32 +0000 (+0400) Subject: runtime: fix spurious deadlock crashes X-Git-Tag: go1.1rc2~2122 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f24323c93e524bfa7d24cd7dcea93c11b983d4d5;p=gostls13.git runtime: fix spurious deadlock crashes Fixes #4243. R=golang-dev, iant CC=golang-dev, sebastien.paolacci https://golang.org/cl/6682050 --- diff --git a/src/pkg/runtime/mheap.c b/src/pkg/runtime/mheap.c index 7463b6bff7..0946adcb9f 100644 --- a/src/pkg/runtime/mheap.c +++ b/src/pkg/runtime/mheap.c @@ -343,6 +343,13 @@ MHeap_FreeLocked(MHeap *h, MSpan *s) runtime·MSpanList_Insert(&h->large, s); } +static void +forcegchelper(Note *note) +{ + runtime·gc(1); + runtime·notewakeup(note); +} + // Release (part of) unused memory to OS. // Goroutine created at startup. // Loop forever. @@ -356,7 +363,7 @@ runtime·MHeap_Scavenger(void) uintptr released, sumreleased; byte *env; bool trace; - Note note; + Note note, *notep; // If we go two minutes without a garbage collection, force one to run. forcegc = 2*60*1e9; @@ -385,7 +392,15 @@ runtime·MHeap_Scavenger(void) now = runtime·nanotime(); if(now - mstats.last_gc > forcegc) { runtime·unlock(h); - runtime·gc(1); + // The scavenger can not block other goroutines, + // otherwise deadlock detector can fire spuriously. + // GC blocks other goroutines via the runtime·worldsema. + runtime·noteclear(¬e); + notep = ¬e; + runtime·newproc1((byte*)forcegchelper, (byte*)¬ep, sizeof(notep), 0, runtime·MHeap_Scavenger); + runtime·entersyscall(); + runtime·notesleep(¬e); + runtime·exitsyscall(); runtime·lock(h); now = runtime·nanotime(); if (trace)