I'm not sure if the channel receive is atomic. I thought it would get a 
null pointer dereference error in chanrecv at runtime.

On Monday, March 2, 2020 at 1:37:01 PM UTC+8, burak serdar wrote:
>
> On Sun, Mar 1, 2020 at 9:49 PM Yuan Ting <yuan...@ict.ac.cn <javascript:>> 
> 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 golan...@googlegroups.com <javascript:>. 
> > 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/bd7c1e5b-a4de-4987-a0bf-b93a105021d5%40googlegroups.com.

Reply via email to