mirror of
https://github.com/golang/go.git
synced 2025-11-12 06:31:05 +00:00
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
This commit is contained in:
parent
e249b0ffee
commit
a0dbbeae67
4 changed files with 19 additions and 5 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue