runtime: block signals in needm before allocating M

Otherwise, if a signal occurs just after we allocated the M,
we can deadlock if the signal handler needs to allocate an M
itself.

Fixes #42207

Change-Id: I76f44547f419e8b1c14cbf49bf602c6e645d8c14
Reviewed-on: https://go-review.googlesource.com/c/go/+/265759
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
Ian Lance Taylor 2020-10-27 16:09:40 -07:00
parent 94f3762462
commit 368c401164
7 changed files with 127 additions and 17 deletions

View file

@ -358,3 +358,12 @@ func TestSignalM(t *testing.T) {
t.Fatalf("signal sent to M %d, but received on M %d", want, got)
}
}
// Issue #42207.
func TestNeedmDeadlock(t *testing.T) {
output := runTestProg(t, "testprogcgo", "NeedmDeadlock")
want := "OK\n"
if output != want {
t.Fatalf("want %s, got %s\n", want, output)
}
}