英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论