>
>
> package main
>
> import "fmt"
>
> func main() {
> ca := createCounter(2)
> cb := createCounter(102)
> for i := 0; i < 5; i++ {
> a := <-ca
> fmt.Printf("A %d \nB %d \n", a, <-cb)
> }
>
> }
>
> func createCounter(start int) chan int {
> next := make(chan int)
> go func(i int) {
> for {
> next <- i
> i++
> }
> }(start)
> return next
> }
>
>
the output is:
A 2
B 102
A 3
B 103
A 4
B 104
A 5
B 105
A 6
B 106
 
could anyone can explain why the output is this?
especially, i don't understand when the goroutine will be destroyed,i think 
when the createCounter() function returned the goroutine will be killed, 
but it seems not ...
thank you






 

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to