Skip to content

Commit

Permalink
runtime: handle windows callback on non-go thread
Browse files Browse the repository at this point in the history
- add comments as per reviewer
  • Loading branch information
billziss-gh committed Jun 3, 2018
1 parent 36a8ac8 commit 51f9bd2
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/runtime/proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,8 @@ func mstart1() {
//go:yeswritebarrierrec
func mstartm0() {
// Create an extra M for callbacks on threads not created by Go.
// An extra M is also needed on Windows for callbacks created by
// syscall.NewCallback.
if (iscgo || GOOS == "windows") && !cgoHasExtraM {
cgoHasExtraM = true
newextram()
Expand Down Expand Up @@ -1620,6 +1622,9 @@ func allocm(_p_ *p, fn func()) *m {
func needm(x byte) {
if (iscgo || GOOS == "windows") && !cgoHasExtraM {
// Can happen if C/C++ code calls Go from a global ctor.
// Can also happen on Windows if a global ctor uses a
// callback created using syscall.NewCallback.
//
// Can not throw, because scheduler is not initialized yet.
write(2, unsafe.Pointer(&earlycgocallback[0]), int32(len(earlycgocallback)))
exit(1)
Expand Down Expand Up @@ -4215,6 +4220,9 @@ func checkdead() {
return
}

// If we are not running under cgo, but we have an extra M then account
// for it. (It is possible to have an extra M on Windows without cgo to
// accommodate callbacks created by syscall.NewCallback.)
var run0 int32
if !iscgo && cgoHasExtraM {
run0 = 1
Expand Down

0 comments on commit 51f9bd2

Please sign in to comment.