keyword "go" in golang, whether go is a atomic operation?

huangapple go评论96阅读模式
英文:

keyword "go" in golang, whether go is a atomic operation?

问题

在Go编程中,我们经常使用以下方式创建一个Go协程:

go func(){}

我想知道关键字"go"是否是一个原子操作,如果使用这个操作创建一个协程失败了会怎么样。

我能否监控新创建的协程是否创建成功?

或者也许关键字"go"创建的协程永远不会失败。

英文:

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.

答案1

得分: 2

spec没有提到创建goroutine或调用函数失败的情况,所以在这一点上的行为取决于实现,没有定义的方法来确定成功或失败

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

英文:

The spec says nothing about failure to create the goroutine or invoke the function, so behavior at this point is up to the implementation and there is no defined way to determine success or failure.

The kinds of errors you would encounter on goroutine creation will be fatal errors (likely due to resource exhaustion), not something that can be caught and handled gracefully. This is similar to the kinds of errors you would encounter on invoking a function.

huangapple
  • 本文由 发表于 2021年8月25日 20:26:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/68922952.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定