]> Cypherpunks repositories - gostls13.git/commit
runtime: make cgocallback wait on package init
authorDavid Crawshaw <crawshaw@golang.org>
Mon, 13 Apr 2015 23:31:39 +0000 (19:31 -0400)
committerDavid Crawshaw <crawshaw@golang.org>
Tue, 14 Apr 2015 13:39:02 +0000 (13:39 +0000)
commit3b22ffc07ec0f4114362425ca004081fcdd708df
tree5a44d7908bf33e4ab7dc1c8d5eed4701f17db318
parentcea272de301e511472ff54905140f526c2ec61f4
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>
misc/cgo/testcarchive/main.c
misc/cgo/testcarchive/src/libgo/libgo.go
src/runtime/cgocall.go
src/runtime/proc.go