On Mon, Mar 2, 2020 at 6:36 AM burak serdar <bser...@computer.org> 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 can panic.

1) The channel receive sees that the channel is non nil
2) The other goroutine concurrently sets the channel to nil
3) GC kicks in and frees the channel memory
4) Something else allocates and overwrites the memory that was
previously used by the channel. That could be the GC itself.
5) The channel receive goroutine now continues to receive using memory
data that are no more representing a channel.

-- 
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/CAA40n-X3oZ3cK37e6CuixNHPZYEMWtQawMyxM2xZ1LXoQJkHBw%40mail.gmail.com.

Reply via email to