From a0dbbeae6785ed7fd15feb4feb4975eded83c191 Mon Sep 17 00:00:00 2001 From: Dmitriy Vyukov Date: Thu, 21 Aug 2014 11:46:53 +0400 Subject: runtime: fix deadlock when gctrace Calling ReadMemStats which does stoptheworld on m0 holding locks was not a good idea. Stoptheworld holding locks is a recipe for deadlocks (added check for this). Stoptheworld on g0 may or may not work (added check for this as well). As far as I understand scavenger will print incorrect numbers now, as stack usage is not subtracted from heap. But it's better than deadlocking. LGTM=khr R=golang-codereviews, rsc, khr CC=golang-codereviews, rlh https://golang.org/cl/124670043 --- src/pkg/runtime/heapdump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/pkg/runtime/heapdump.c') diff --git a/src/pkg/runtime/heapdump.c b/src/pkg/runtime/heapdump.c index 63d80b8d0e..a2d12ad603 100644 --- a/src/pkg/runtime/heapdump.c +++ b/src/pkg/runtime/heapdump.c @@ -748,7 +748,6 @@ runtime∕debug·WriteHeapDump(uintptr fd) // Stop the world. runtime·semacquire(&runtime·worldsema, false); g->m->gcing = 1; - g->m->locks++; runtime·stoptheworld(); // Update stats so we can dump them. @@ -774,6 +773,7 @@ runtime∕debug·WriteHeapDump(uintptr fd) // Start up the world again. g->m->gcing = 0; + g->m->locks++; runtime·semrelease(&runtime·worldsema); runtime·starttheworld(); g->m->locks--; -- cgit v1.3