* 'andreas graeper' via golang-nuts <[email protected]> [260608 
05:43]:
> 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 

People are having trouble helping you because you did not give a
complete, runnable example.  You should use the Go Playground,
https://go.dev/play/, to demonstrate your problem, and use the "Share"
button to include a link to the code in your message.

For example, the code at https://go.dev/play/p/fu0r16PNocY demonstrates
the problem you are having, and from that it would have been clear to
the others who were trying to help you that the problem is on line 49,
where c is declared but not initialized.  (Technically, it is
initialized to nil.)  If you change that line to

    var c = make(chan int)

then the code executes the way you expected.

The code you gave in your message was the part that was correct.  It was
the part of your code that you did not include that contained the error,
so helping you required significantly more effort and a lot of guessing.
(I'm still guessing, but from your description of the symptoms, I have a
reasonable expectation that my analysis is correct.)

...Marvin

-- 
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/aibi2KAdNzkks/Bd%40basil.wdw.

Reply via email to