Skip to content

Commit 6f7c9ea

Browse files
WangLeonardgopherbot
authored andcommitted
runtime: set userForced while holding gcsema
Fixes #52515 Change-Id: If10068a97733daf61aba72da5ed3935db8eed8b9 Reviewed-on: https://go-review.googlesource.com/c/go/+/401776 Reviewed-by: hopehook <[email protected]> Run-TryBot: hopehook <[email protected]> Reviewed-by: Michael Knyszek <[email protected]> Auto-Submit: Jenny Rakoczy <[email protected]> Run-TryBot: Michael Knyszek <[email protected]> Reviewed-by: Jenny Rakoczy <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 242adb7 commit 6f7c9ea

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/runtime/mgc.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -612,9 +612,6 @@ func gcStart(trigger gcTrigger) {
612612
return
613613
}
614614

615-
// For stats, check if this GC was forced by the user.
616-
work.userForced = trigger.kind == gcTriggerCycle
617-
618615
// In gcstoptheworld debug mode, upgrade the mode accordingly.
619616
// We do this after re-checking the transition condition so
620617
// that multiple goroutines that detect the heap trigger don't
@@ -630,6 +627,10 @@ func gcStart(trigger gcTrigger) {
630627
semacquire(&gcsema)
631628
semacquire(&worldsema)
632629

630+
// For stats, check if this GC was forced by the user.
631+
// Update it under gcsema to avoid gctrace getting wrong values.
632+
work.userForced = trigger.kind == gcTriggerCycle
633+
633634
if trace.enabled {
634635
traceGCStart()
635636
}

0 commit comments

Comments
 (0)