package main
import (
"fmt"
"math/rand"
)
func push(c chan []int) {
var slice []int
for num, i := rand.Intn(5)+1, 0; i <= num; i++ {
slice = append(slice, rand.Intn(100))
}
c <- slice
}
func main() {
c := make(chan []int)
go push(c)
// go push(c)
x, y := <-c, <-c
fmt.Println("x:", x, "y:", y)
}
deadlock原因:
chanel缓冲里的资源只有一个,x和y竞争导致环路
有疑问加站长微信联系(非本文作者)