]> Cypherpunks repositories - gostls13.git/commit
runtime: put a bool in front of initialization-done channel
authorIan Lance Taylor <iant@golang.org>
Tue, 10 Feb 2026 18:17:58 +0000 (10:17 -0800)
committerGopher Robot <gobot@golang.org>
Wed, 11 Feb 2026 02:43:34 +0000 (18:43 -0800)
commit4f8aa414f0ff4af04df1554113178ee57959c706
treed6bcbbd6bcdcf5aeb6316e4f55d6e50a66f39100
parent97c48fd93db95f56849395cf8c7447232d56607a
runtime: put a bool in front of initialization-done channel

Calls to Go functions from threads not started by Go have to wait
for Go initialization to be complete. Before this CL they did this
by receiving from a channel that is closed when initialization is done.
That works well but introduces a channel operation into cgo calls.
This is particularly frustrating because the channel is approximately
always closed.

This CL adds an atomic bool before the channel, so that in the normal
case we are just adding a single locked memory load. We still use
the channel as a fallback.

For #77522

Change-Id: I8f609bf349bb0f836cefa5f6ad6d0c3c7bbfe5e0
Reviewed-on: https://go-review.googlesource.com/c/go/+/743940
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
src/runtime/cgocall.go
src/runtime/proc.go