aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/runtime/malloc.go
diff options
context:
space:
mode:
authorDmitriy Vyukov <dvyukov@google.com>2014-08-21 11:46:53 +0400
committerDmitriy Vyukov <dvyukov@google.com>2014-08-21 11:46:53 +0400
commita0dbbeae6785ed7fd15feb4feb4975eded83c191 (patch)
tree8018db3784aac053b54d88d9259108280d41f28a /src/pkg/runtime/malloc.go
parente249b0ffeeb36957adfde2b3ec3ab0eabea8e3ba (diff)
downloadgo-a0dbbeae6785ed7fd15feb4feb4975eded83c191.tar.xz
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
Diffstat (limited to 'src/pkg/runtime/malloc.go')
-rw-r--r--src/pkg/runtime/malloc.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/pkg/runtime/malloc.go b/src/pkg/runtime/malloc.go
index 8ee460755f..578fbd1c2d 100644
--- a/src/pkg/runtime/malloc.go
+++ b/src/pkg/runtime/malloc.go
@@ -413,6 +413,7 @@ func gogc(force int32) {
return
}
releasem(mp)
+ mp = nil
if panicking != 0 {
return
@@ -441,7 +442,11 @@ func gogc(force int32) {
startTime := gonanotime()
mp = acquirem()
mp.gcing = 1
+ releasem(mp)
stoptheworld()
+ if mp != acquirem() {
+ gothrow("gogc: rescheduled")
+ }
clearpools()
@@ -474,6 +479,7 @@ func gogc(force int32) {
semrelease(&worldsema)
starttheworld()
releasem(mp)
+ mp = nil
// now that gc is done, kick off finalizer thread if needed
if !concurrentSweep {