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 <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
At this point, channel receive is still holding a reference to the channel (right?), so GC cannot free it. > 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/CAMV2RqqkiUh0x5q20O%2B_i80sWw9vmKuGUDR7hYVzbDKk5e%3D0bA%40mail.gmail.com.