首页 > 解决方案 > keyword "go" in golang, whether go is a atomic operation?

问题描述

in go programing, we always create a go routine like

go func(){}

i want to know whether keyword "go" is an atomic operation, what if create a go routine fail by this operation.

can i monitor a new go routine created success or not?

Or maybe this keyword "go" create a routine that will never fail.

标签: go

解决方案


规范没有说明创建 goroutine 或调用函数失败,因此此时的行为取决于实现,并且没有定义确定成功或失败的方法。

您在创建 goroutine 时会遇到的错误类型将是致命错误(可能是由于资源耗尽),而不是可以被优雅地捕获和处理的错误。这类似于您在调用函数时会遇到的各种错误。


推荐阅读