【发布时间】:2019-04-08 11:24:15
【问题描述】:
我正在开发一个示例程序,以使用具有多个通道的 goroutine 打印 1 到 100 之间的奇数和偶数之和。
你可以找到我的代码
输出
sum of even number = 2550
sum of odd number = 2500
fatal error: all goroutines are asleep - deadlock!
goroutine 1 [chan receive]:
main.print(0x434100, 0x11db7c)
/tmp/sandbox052575152/main.go:18 +0xc0
main.main()
/tmp/sandbox052575152/main.go:14 +0x120
代码可以工作,但会出现死锁。 我不确定我的代码有什么问题
【问题讨论】: