package main import "fmt" func main() { targetIndice := make([]int, 3) targetIndice[0] = 5 targetIndice[2] = 4 for i,n := range targetIndice{ fmt.Printf("%d : %d \n", i, n) } c := make(chan int) for i, n:= range targetIndice{ go func(){ fmt.Printf("targetIndice[%d]=%d \n", i, n) c <- 1 }() } for i:=0; i<3; i++{ <- c } }
-----go run main.go--------- 0 : 5 1 : 0 2 : 4 targetIndice[2]=4 targetIndice[2]=4 targetIndice[2]=4 -- 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/03ebf86c-5ec9-486e-81c1-c8126b83deddn%40googlegroups.com.