diff options
| author | Cherry Mui <cherryyz@google.com> | 2026-02-18 11:33:56 -0500 |
|---|---|---|
| committer | Cherry Mui <cherryyz@google.com> | 2026-02-18 10:38:22 -0800 |
| commit | f40560ff89eac34709f5fee56ebf71bfb2c4065c (patch) | |
| tree | 30beba378423a143391fb59c6c62219b89022a7f /src/runtime | |
| parent | 50b63f6cb90a1437ca6756ede016f1918e721da6 (diff) | |
| download | go-f40560ff89eac34709f5fee56ebf71bfb2c4065c.tar.xz | |
runtime: tell the race detector about synchronization on mainInitDone
CL 743940 puts an atomic bool initialization-done channel, which
is a nice optimization. In race mode, however, the atomic bool
does not have race instrumentation, so the race detector doesn't
know the happens-before edge between the initialization and the
cgo callback.
To tell the race detector about this synchronization, just use the
channel unconditionally in race mode. Channel operations have the
proper race instrumentation. Alternatively, we could explicitly
instrument the atomic boolean operations.
TODO: write a test.
Change-Id: I466b20a46cd39d2bbe2149a9009e1a01b15891e2
Reviewed-on: https://go-review.googlesource.com/c/go/+/746581
Reviewed-by: Ian Lance Taylor <iant@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'src/runtime')
| -rw-r--r-- | src/runtime/cgocall.go | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/runtime/cgocall.go b/src/runtime/cgocall.go index 7f05c13aee..626f7edf01 100644 --- a/src/runtime/cgocall.go +++ b/src/runtime/cgocall.go @@ -428,7 +428,10 @@ func cgocallbackg1(fn, frame unsafe.Pointer, ctxt uintptr) { // // We check a bool first for speed, and wait on a channel // if it's not ready. - if !mainInitDone.Load() { + // + // In race mode, skip the optimization and always use the + // channel, which has the race instrumentation. + if raceenabled || !mainInitDone.Load() { <-mainInitDoneChan } } |
