diff options
| author | David Chase <drchase@google.com> | 2023-12-14 14:20:12 -0500 |
|---|---|---|
| committer | David Chase <drchase@google.com> | 2023-12-15 20:30:44 +0000 |
| commit | 3313bbb4055f38f53cd43c6c5782a229f445f230 (patch) | |
| tree | dc21ea7c327d01b9c34a1509c1ca06f26bcd4c43 /src/runtime/runtime.go | |
| parent | b60bf8f8e131b026eb2691e736d3df9dce852297 (diff) | |
| download | go-3313bbb4055f38f53cd43c6c5782a229f445f230.tar.xz | |
runtime: add race annotations in IncNonDefault
Also use CompareAndSwap to make the code actually less racy.
Added a test which will be meaningful when run under the race
detector (tested it -race with broken fix in runtime, it failed).
Fixes #64649
Change-Id: I5972e08901d1adc8ba74858edad7eba91be1b0ce
Reviewed-on: https://go-review.googlesource.com/c/go/+/549796
Run-TryBot: David Chase <drchase@google.com>
Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/runtime/runtime.go')
| -rw-r--r-- | src/runtime/runtime.go | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/runtime/runtime.go b/src/runtime/runtime.go index 0829a84e43..92cdfc310e 100644 --- a/src/runtime/runtime.go +++ b/src/runtime/runtime.go @@ -172,7 +172,15 @@ func (g *godebugInc) IncNonDefault() { // *godebug.Setting. inc = new(func()) *inc = (*newInc)(g.name) - g.inc.Store(inc) + if raceenabled { + racerelease(unsafe.Pointer(&g.inc)) + } + if !g.inc.CompareAndSwap(nil, inc) { + inc = g.inc.Load() + } + } + if raceenabled { + raceacquire(unsafe.Pointer(&g.inc)) } (*inc)() } |
