os/signal: lazily start signal watch loop only on Notify

By lazily starting the signal watch loop only on Notify,
we are able to have deadlock detection even when
"os/signal" is imported.

Thanks to Ian Lance Taylor for the solution and discussion.

With this change in, fix a runtime gorountine count test that
assumed that os/signal.init would unconditionally start the
signal watching goroutine, but alas no more.

Fixes #21576.

Change-Id: I6eecf82a887f59f2ec8897f1bcd67ca311ca42ff
Reviewed-on: https://go-review.googlesource.com/c/go/+/101036
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Emmanuel T Odeke 2019-03-11 10:52:00 -07:00 committed by Emmanuel Odeke
parent a1b0af9904
commit e79b57d6c4
5 changed files with 79 additions and 9 deletions

View file

@ -26,7 +26,8 @@ func loop() {
func init() {
signal_enable(0) // first call - initialize
go loop()
watchSignalLoop = loop
}
const (