Skip to content

Commit 51f9bd2

Browse files
committed
runtime: handle windows callback on non-go thread
- add comments as per reviewer
1 parent 36a8ac8 commit 51f9bd2

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/runtime/proc.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,6 +1293,8 @@ func mstart1() {
12931293
//go:yeswritebarrierrec
12941294
func mstartm0() {
12951295
// Create an extra M for callbacks on threads not created by Go.
1296+
// An extra M is also needed on Windows for callbacks created by
1297+
// syscall.NewCallback.
12961298
if (iscgo || GOOS == "windows") && !cgoHasExtraM {
12971299
cgoHasExtraM = true
12981300
newextram()
@@ -1620,6 +1622,9 @@ func allocm(_p_ *p, fn func()) *m {
16201622
func needm(x byte) {
16211623
if (iscgo || GOOS == "windows") && !cgoHasExtraM {
16221624
// Can happen if C/C++ code calls Go from a global ctor.
1625+
// Can also happen on Windows if a global ctor uses a
1626+
// callback created using syscall.NewCallback.
1627+
//
16231628
// Can not throw, because scheduler is not initialized yet.
16241629
write(2, unsafe.Pointer(&earlycgocallback[0]), int32(len(earlycgocallback)))
16251630
exit(1)
@@ -4215,6 +4220,9 @@ func checkdead() {
42154220
return
42164221
}
42174222

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

0 commit comments

Comments
 (0)