From: Cherry Mui Date: Wed, 20 Dec 2023 19:33:46 +0000 (-0500) Subject: runtime: use racereleasemerge for godebugInc X-Git-Tag: go1.22rc2~8^2~23 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=0b56804084eb75495e704921f71e4f215fced6b7;p=gostls13.git runtime: use racereleasemerge for godebugInc CL 549796 adds race annotations to godebugInc. It uses racerelease to model a CompareAndSwap. However, a CompareAndSwap is essentially a load and a store. Modeling it as just racerelease makes it not synchronized with other racerelease, i.e. other CAS. For the following execution thread A B load, got nil load, got nil set *inc set *inc racerelease CAS success racerelease CAS fail load raceacquire use *inc (from A) On thread B, the raceacquire synchronizes with the previous racerelease, which is not synchronized with racerelease on thread A, so it doesn't know that the use of *inc on thread B is after the set on thread A, and will report a race. Change it to use racereleasemerge, which synchronizes with previous racerelease and racereleasemerge. So in the case above it knows thread B's CAS is after thread A's. Also remove stale comment that was more relevant when the code used atomic store, where CL 549796 changed to CAS. Updates #64649. Change-Id: I17671090a19c0699fcb4e6481e2abd98ef2e5542 Reviewed-on: https://go-review.googlesource.com/c/go/+/551856 Reviewed-by: Mauri de Souza Meneguzzo LUCI-TryBot-Result: Go LUCI Reviewed-by: David Chase --- diff --git a/src/runtime/runtime.go b/src/runtime/runtime.go index 92cdfc310e..c70a76e409 100644 --- a/src/runtime/runtime.go +++ b/src/runtime/runtime.go @@ -167,13 +167,10 @@ func (g *godebugInc) IncNonDefault() { if newInc == nil { return } - // If other goroutines are racing here, no big deal. One will win, - // and all the inc functions will be using the same underlying - // *godebug.Setting. inc = new(func()) *inc = (*newInc)(g.name) if raceenabled { - racerelease(unsafe.Pointer(&g.inc)) + racereleasemerge(unsafe.Pointer(&g.inc)) } if !g.inc.CompareAndSwap(nil, inc) { inc = g.inc.Load()