我已經做了一段時間了,但仍然無法弄清楚為什么會出現這種死鎖(https://play.golang.org/p/INeUl_ktMJA):package mainimport ( "context" "time")func main() { ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) t := time.NewTicker(time.Second) for range t.C { select { case <-ctx.Done(): t.Stop() default: print(".") } } cancel()}我希望關閉的上下文關閉應該退出范圍循環并因此清理上下文的股票通道。反而:...fatal error: all goroutines are asleep - deadlock!goroutine 1 [chan receive]:main.main() /Users/andig/htdocs/test.go:12 +0xafexit status 2
- 1 回答
- 0 關注
- 189 瀏覽
添加回答
舉報
0/150
提交
取消