golang goroutine 父子关系
作者:互联网
很多人认为 父 goroutine 结束后 子goroutine 一定会结束
结论只要main 不结束 goroutine 一定会运行
代码验证
package main
import (
"fmt"
"time"
)
func main() {
fmt.Println("main start")
go func() {
fmt.Println("parent start")
go func() {
fmt.Println("son start")
time.Sleep(1 * time.Second)
fmt.Println("son start")
}()
fmt.Println("parent end")
}()
time.Sleep(3 * time.Second)
fmt.Println("main end")
}
/*main start
parent start
parent end
son start
son start
main end*/
标签:父子关系,fmt,goroutine,son,golang,start,time,Println,main 来源: https://www.cnblogs.com/guanchaoguo/p/16208116.html