在主要的goroutine中,如果我将值发送到超过容量的通道,我就会陷入死锁,但是如果我发送的是不同的goroutine,就不会出现死锁,为什么?
func main() {
c := make(chan int, 2)
for i := 0; i < 3; i++ {
c <- i
}
}
func main() {
c := make(chan int, 2)
go func() {
for i := 0; i < 3; i++ {
c <- i
}
close(c)
}()
time.Sleep(5 * time.Second)
}发布于 2021-12-14 07:08:13
func main() {
c := make(chan int, 2)
for i := 0; i < 3; i++ {
// Blocking operation
c <- i
}
}By default >>>sends<<< and receives block(!) until both the sender and receiver are ready结帐- https://gobyexample.com/channels
您的频道上没有接收者,主接收方被封锁。
https://stackoverflow.com/questions/70343475
复制相似问题