From f069a8299876f9987a01a8d4a664d2a887bd5efc Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Tue, 24 Jun 2025 16:33:10 -0400 Subject: runtime: note custom GOMAXPROCS even if value doesn't change When an application calls runtime.GOMAXPROCS(runtime.GOMAXPROCS(0)), the runtime does not need to change the actual GOMAXPROCS value (via STW). However, this call must still transition from "automatic" to "custom" GOMAXPROCS state, thus disabling background updates. Thus this case shouldn't return quite as early as it currently does. Change-Id: I6a6a636c42f73996532bd9f7beb95e933256c9e7 Reviewed-on: https://go-review.googlesource.com/c/go/+/683815 Reviewed-by: Michael Knyszek Reviewed-by: Carlos Amedee LUCI-TryBot-Result: Go LUCI Auto-Submit: Michael Pratt --- src/runtime/debug.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/runtime/debug.go') diff --git a/src/runtime/debug.go b/src/runtime/debug.go index bdaaa7196d..c7592d3329 100644 --- a/src/runtime/debug.go +++ b/src/runtime/debug.go @@ -39,7 +39,7 @@ func GOMAXPROCS(n int) int { lock(&sched.lock) ret := int(gomaxprocs) - if n <= 0 || n == ret { + if n <= 0 { unlock(&sched.lock) return ret } @@ -52,6 +52,12 @@ func GOMAXPROCS(n int) int { lock(&computeMaxProcsLock) unlock(&computeMaxProcsLock) + if n == ret { + // sched.customGOMAXPROCS set, but no need to actually STW + // since the gomaxprocs itself isn't changing. + return ret + } + stw := stopTheWorldGC(stwGOMAXPROCS) // newprocs will be processed by startTheWorld -- cgit v1.3