我是新手golang(具有Java并發背景)??紤]一下代碼的和平:package mainimport "fmt"func sendenum(num int, c chan int) { c <- num}func main() { c := make(chan int) go sendenum(0, c) x, y := <-c, <-c fmt.Println(x, y)}當我運行此代碼時,出現此錯誤fatal error: all goroutines are asleep - deadlock!goroutine 1 [chan receive]:main.main() /home/tarrsalah/src/go/src/github.com/tarrsalah/stackoverflow/chan_dead_lock.go:12 +0x90exit status 2我知道,添加另一條go sendenum(0, c)語句可以解決問題,...但是當與凡僵局發生了什么?
- 2 回答
- 0 關注
- 161 瀏覽
添加回答
舉報
0/150
提交
取消