duanlv4984
2017-10-27 17:17
浏览 50
已采纳

从调用另一个goroutine的goroutine返回

I wonder what happens to goroutines called from another goroutine when it returns. Do they continue running or get terminated? Here is a sample code to show what I mean:

func func() {
    // Doing something
}

func func2() {
        go func()
        // Doing things that end with a return
    }

func main() {
    go func2()
}

what happens to func() goroutine when func2() goroutine returns?

图片转代码服务由CSDN问答提供 功能建议

我想知道从另一个goroutine返回的goroutine会如何处理。 它们是继续运行还是被终止? 这是示例代码来显示我的意思:

  func func(){
 //做某事
} 
  
func func2(){
 go func()
 //做以返回结尾的事情
} 
 
func main(){
 go func2()
} 
  <  / pre> 
 
 

当func2()goroutine返回时,func()goroutine会发生什么?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongzhi7641 2017-10-27 18:03
    已采纳

    You can make an experiment on excellent https://play.golang.org playground! I recommend experiment there - it helps very much with golang studying.

    https://play.golang.org/p/OJ9sgakV-S

    I've added 2 second delay, because if program exit too quickly, you 'll not see results from goroutines.

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题