代码如下,为啥是轮循打印两遍
package main
import (
"fmt"
)
func main() {
ch := make(chan int)
go func() {
for i := 0; i <= 5; i++ {
fmt.Println("子go程写",i)
ch <- i
}
}()
for i := 0; i <= 5; i++ {
j := <-ch
fmt.Println("主go程读", j)
}
}
![image.png](https://static.studygolang.com/220310/c87b5e2439cf5efeb3c3835c292a35d6.png)
有疑问加站长微信联系(非本文作者))