我的代码如下:
package main
import (
"fmt"
)
func main() {
c1 := make(chan int)
fmt.Println("push c1: ")
c1 <- 10
g1 := <- c1
fmt.Println("get g1: ", g1)
}
Run Code Online (Sandbox Code Playgroud)
当我使用 delve 进行调试时,它会打印以下结果:
push c1:
fatal error: all goroutines are asleep - deadlock!
goroutine 1 [chan send]:
main.main()
D:/Go/projects/hello-world/src/ch9/code9_6/code1.go:10 +0xde
Process 6276 has exited with status 2
Run Code Online (Sandbox Code Playgroud)
我不知道为什么,这只是一个简单的渠道示例,我创建了一个渠道,向其发送价值并从中获取价值,仅此而已,有人可以告诉我为什么,以及如何纠正它,非常感谢。