Re: [go-nuts] Should it panic when set a channel to nil concurrently

2020-03-02 Thread Jake Montgomery
Good explanation, Marvin. This is precisely why we have the race detector. If all races produced a panic, then it would not be needed. Some races behave "correctly" for a long time, and only on rare occasion result in silent data corruption that can be almost impossible to debug. Other races mi

Re: [go-nuts] Should it panic when set a channel to nil concurrently

2020-03-02 Thread Marvin Renich
* Yuan Ting [200301 23:50]: > 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 pani

Re: [go-nuts] Should it panic when set a channel to nil concurrently

2020-03-01 Thread Yuan Ting
How about the main go compiler? Will the code generated by the main go compiler panic as you analyze? On Monday, March 2, 2020 at 2:11:47 PM UTC+8, Jan Mercl wrote: > > On Mon, Mar 2, 2020 at 6:56 AM burak serdar > wrote: > > > At this point, channel receive is still holding a reference to the

Re: [go-nuts] Should it panic when set a channel to nil concurrently

2020-03-01 Thread Yuan Ting
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 > > wrote: > > > > I write a simple program likes below

Re: [go-nuts] Should it panic when set a channel to nil concurrently

2020-03-01 Thread Jan Mercl
On Mon, Mar 2, 2020 at 6:56 AM burak serdar wrote: > At this point, channel receive is still holding a reference to the > channel (right?), so GC cannot free it. Depends very much on what code the compiler for channel receive generates and on the code in the runtime that implements the channel r

Re: [go-nuts] Should it panic when set a channel to nil concurrently

2020-03-01 Thread burak serdar
On Sun, Mar 1, 2020 at 10:49 PM Jan Mercl <0xj...@gmail.com> wrote: > > On Mon, Mar 2, 2020 at 6:36 AM burak serdar wrote: > > > 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

Re: [go-nuts] Should it panic when set a channel to nil concurrently

2020-03-01 Thread Jan Mercl
On Mon, Mar 2, 2020 at 6:36 AM burak serdar wrote: > 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. It ca

Re: [go-nuts] Should it panic when set a channel to nil concurrently

2020-03-01 Thread burak serdar
On Sun, Mar 1, 2020 at 9:49 PM Yuan Ting 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

[go-nuts] Should it panic when set a channel to nil concurrently

2020-03-01 Thread Yuan Ting
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. ch