Re: [go-nuts] Persistence of value, or Safely close what you expected

2019-03-13 Thread Marcin Romaszewicz
Your program is most certainly non-deterministic, and you will sometimes close a closed channel and panic. There is no thread safe way to test if a channel is closed, then close it if it isn't. I think of channel ownership in a similar way as of memory ownership in C/C++. If this channel is being

Re: [go-nuts] Persistence of value, or Safely close what you expected

2019-03-13 Thread Andrei Tudor Călin
Hello. I apologize if my previous mail was cut unexpectedly short. My e-mail client did something that I do not completely understand. ISTM that there are no guarantees about the behavior of that program at all. Access to c from niller and closer is not synchronized, so it's not really possible

[go-nuts] Persistence of value, or Safely close what you expected

2019-03-13 Thread Andrey Tcherepanov
Hello fellow Go devs, I have a question that probably is a bit weird and obvious, but here we go package main var c chan int func niller() { c = nil } func closer() { close(c) } func main() { c = make(chan int, 1) go closer() go niller() // checkpoint-1 if c != nil { // checkpoint-2