报错代码展示:
func testDeadLock(c chan int){
for{
fmt.Println(<-c)
}
}
func main() {
c :=make(chan int)
c<-'A'
go testDeadLock(c)
time.Sleep(time.Millisecond)
}
channel无缓冲时,是阻塞的
https://blog.youkuaiyun.com/u011328417/article/details/89473323
本文通过一个具体的报错案例,探讨了在Golang中使用无缓存channel可能导致的goroutine死锁问题。当channel无缓冲时,发送和接收操作会立即阻塞,如果不正确地使用,将造成程序的死锁状态。
报错代码展示:
func testDeadLock(c chan int){
for{
fmt.Println(<-c)
}
}
func main() {
c :=make(chan int)
c<-'A'
go testDeadLock(c)
time.Sleep(time.Millisecond)
}
channel无缓冲时,是阻塞的
https://blog.youkuaiyun.com/u011328417/article/details/89473323

被折叠的 条评论
为什么被折叠?