Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.4开头对init函数中启动新goroutine的描述有错误 #560

Closed
developerdong opened this issue Dec 18, 2021 · 1 comment · Fixed by #592
Closed

1.4开头对init函数中启动新goroutine的描述有错误 #560

developerdong opened this issue Dec 18, 2021 · 1 comment · Fixed by #592
Assignees

Comments

@developerdong
Copy link
Contributor

要注意的是,在main.main函数执行之前所有代码都运行在同一个goroutine,也就是程序的主系统线程中。因此,如果某个init函数内部用go关键字启动了新的goroutine的话,新的goroutine只有在进入main.main函数之后才可能被执行到。

执行这段代码 可以发现新的goroutine在init函数结束之前,也就是main函数开始之前就执行了,与文中所说不符。

@huanqingdong
Copy link

huanqingdong commented Feb 17, 2022

亲测, 不符 (go version go1.17.3 darwin/amd64)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants