This happens because once you've walked and consumed every node in the entire tree, you're left with exactly one running goroutine, the one in the main function waiting for new elements in the channel. If you close the channel, the for loop closes. If you don't, it's the only thread left running and the runtime notices there are no new goroutines capable of doing anything.
On Mon, Jun 8, 2026, 12:42 'andreas graeper' via golang-nuts < [email protected]> wrote: > hi. i try to walk through a tree putting elems into channel > w(t,c) { if t!=nil { w(t.left,c) ; c<-t.elem ; w(t.right,c) }} > w0(t,c) { w(t,c); close(c); } > main(){ > go w0(t,c) > for e := range c {} > } > if i drop 'close(c)' i get 'all threads dead' , otherwise 'write after > close' > it feels as if w is send to background too and i have to sync to the end > of w before i close the channel ? > thanks in advance, andi > > -- > 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 [email protected]. > To view this discussion visit > https://groups.google.com/d/msgid/golang-nuts/4a665d05-d769-4249-a6df-4e3de0589d1an%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/4a665d05-d769-4249-a6df-4e3de0589d1an%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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 [email protected]. To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/CADgY6e_xEcxtS5_bfCdDEAQnmWby1PNCKaX3qSfAtbCwXakUiA%40mail.gmail.com.
