main 只是一个普通的 goroutine 吗?

Is main just a normal goroutine?

我目前正在阅读 Go 并发模式 的片段。我对 slide #16:

上的声明之间看似矛盾感到有点困惑

When main returns, the program exits and takes the boring function down with it.

slide #19 (in combination with the example on slide #20 上的另一个):

A channel in Go provides a connection between two goroutines, allowing them to communicate.

如果main 只是一个goroutine,它怎么会导致任何另一个(产生的)goroutine停止,换句话说:goroutine在什么意义上被命名为main特别?*


* 我搜索了一下,但到目前为止没有发现任何明显的启发;具有前途标题 Difference between the main goroutine and spawned goroutines of a Go program 的 SO 问题要求一个完全不同的问题。

编辑: 更改了标题,重点关注 main 和 "normal" goroutines 之间的区别(在偶然发现 Go 运行时函数 Goexit 之后)

编辑: 简化问题,更加关注 main

的细节

我认为您需要将 goroutine 影响与流程影响分开考虑。

main() 函数是一个 goroutine(或者如果你真的想挑剔的话,从一个隐式创建的 goroutine 调用)。使用 go 创建其他 goroutines。从 main() 返回会终止其 goroutine,但也会终止整个进程(以及所有其他 goroutine)。也可以通过从任何 goroutine 调用 os.Exit() 或类似的方法来终止整个过程。