aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/proc.go
diff options
context:
space:
mode:
authorDavid Crawshaw <crawshaw@golang.org>2015-04-13 19:31:39 -0400
committerDavid Crawshaw <crawshaw@golang.org>2015-04-14 13:39:02 +0000
commit3b22ffc07ec0f4114362425ca004081fcdd708df (patch)
tree5a44d7908bf33e4ab7dc1c8d5eed4701f17db318 /src/runtime/proc.go
parentcea272de301e511472ff54905140f526c2ec61f4 (diff)
downloadgo-3b22ffc07ec0f4114362425ca004081fcdd708df.tar.xz
runtime: make cgocallback wait on package init
With the new buildmodes c-archive and c-shared, it is possible for a cgo call to come in early in the lifecycle of a Go program. Calls before the runtime has been initialized are caught by _cgo_wait_runtime_init_done. However a call can come in after the runtime has initialized, but before the program's package init functions have finished running. To avoid this cgocallback checks m.ncgo to see if we are on a thread running Go. If not, we may be a foreign thread and it blocks until main_init is complete. Change-Id: I7a9f137fa2a40c322a0b93764261f9aa17fcf5b8 Reviewed-on: https://go-review.googlesource.com/8897 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: David Crawshaw <crawshaw@golang.org>
Diffstat (limited to 'src/runtime/proc.go')
-rw-r--r--src/runtime/proc.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/runtime/proc.go b/src/runtime/proc.go
index 7b6183d905..50f9dd7f52 100644
--- a/src/runtime/proc.go
+++ b/src/runtime/proc.go
@@ -12,6 +12,12 @@ func runtime_init()
//go:linkname main_init main.init
func main_init()
+// main_init_done is a signal used by cgocallbackg that initialization
+// has been completed. It is made before _cgo_notify_runtime_init_done,
+// so all cgo calls can rely on it existing. When main_init is complete,
+// it is closed, meaning cgocallbackg can reliably receive from it.
+var main_init_done chan bool
+
//go:linkname main_main main.main
func main_main()
@@ -70,6 +76,7 @@ func main() {
// Allocate new M as main_main() is expected to block forever.
systemstack(newextram)
}
+ main_init_done = make(chan bool)
if iscgo {
if _cgo_thread_start == nil {
throw("_cgo_thread_start missing")
@@ -95,6 +102,7 @@ func main() {
}
main_init()
+ close(main_init_done)
needUnlock = false
unlockOSThread()