mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 02:35:53 +08:00
@@ -114,7 +114,7 @@ Washington Tripoli London Beijing tokyo
|
||||
---- Error run E:/Go/Goboek/code examples/chapter 14/goroutine2.exe with code Crashed ---- Program exited with code -2147483645: panic: all goroutines are asleep-deadlock!
|
||||
```
|
||||
|
||||
为什么会这样?运行时会检查所有的协程(也许只有一个是这种情况)是否在等待(可以读取或者写入某个通道),意味着程序无法处理。这是死锁(deadlock)形式,运行时可以检测到这种情况。
|
||||
为什么会这样?运行时(runtime)会检查所有的协程(像本例中只有一个)是否在等待着什么东西(可从某个通道读取或者写入某个通道),这意味着程序将无法继续执行。这是死锁(deadlock)的一种形式,而运行时(runtime)可以为我们检测到这种情况。
|
||||
|
||||
注意:不要使用打印状态来表明通道的发送和接收顺序:由于打印状态和通道实际发生读写的时间延迟会导致和真实发生的顺序不同。
|
||||
|
||||
@@ -169,7 +169,6 @@ func suck(ch chan int) {
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
在 `main()` 中使用协程开始它:
|
||||
|
||||
```go
|
||||
|
Reference in New Issue
Block a user