We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A process can't use os/signal.Notify inside a goroutine to signal itself with SIGUSR2.
Works as expected (outside the goroutine):
func main() { var c = make(chan os.Signal, 1) signal.Notify(c) // outside the goroutine var done = make(chan struct{}) go func() { fmt.Println(<-c) done <- struct{}{} }() if err := syscall.Kill(os.Getpid(), syscall.SIGUSR2); err != nil { panic(err) } <-done }
Doesn't work as expected (inside the goroutine):
func main() { var done = make(chan struct{}) go func() { var c = make(chan os.Signal, 1) signal.Notify(c) // inside the goroutine fmt.Println(<-c) done <- struct{}{} }() if err := syscall.Kill(os.Getpid(), syscall.SIGUSR2); err != nil { panic(err) } <-done }
Expected: Doesn't hang Actual: Hangs
The Notify documentation doesn't say it has to be called in the main goroutine.
The text was updated successfully, but these errors were encountered:
Beware of race conditions...
func main() { var done = make(chan struct{}) var doneReg = make(chan struct{}) go func() { var c = make(chan os.Signal, 1) signal.Notify(c) // inside the goroutine doneReg <- struct{}{} //signal registration fmt.Println(<-c) done <- struct{}{} }() <-doneReg //wait for registration if err := syscall.Kill(os.Getpid(), syscall.SIGUSR2); err != nil { panic(err) } <-done }
Marvin
Sorry, something went wrong.
Ouch, didn't see it. Thanks!
No branches or pull requests
A process can't use os/signal.Notify inside a goroutine to signal itself with SIGUSR2.
Works as expected (outside the goroutine):
Doesn't work as expected (inside the goroutine):
Expected: Doesn't hang
Actual: Hangs
The Notify documentation doesn't say it has to be called in the main goroutine.
The text was updated successfully, but these errors were encountered: