On Sun, Mar 1, 2020 at 9:49 PM Yuan Ting <yuant...@ict.ac.cn> wrote: > > I write a simple program likes below and it triggers a data race alarm with > -race flag. But no matter how I run, this program will not panic. I know it > is legal to receive messages from nil channels, but I don't quite understand > why this program does not panic in the presence of data races.
Why should it panic? The first goroutine simply sets the channel to nil. The second goroutine will either block reading from a non-nil channel, or block reading from a nil channel. There is no code in this program that would panic. > > ch := make(chan struct{}) > go func() { > ch = nil > }() > go func() { > <-ch > }() > > > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/02e2fa3e-1952-4dda-8bfa-18f619e21ec9%40googlegroups.com. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAMV2Rqr%3Dt%3Db%2BG8oyM4Yeiz_k4dJkygAG8ocmJFCg_x0ROFk1GQ%40mail.gmail.com.