Golang learning 并发 Goroutine

func main()  {

    go fmt.Println(1)     go 关键字 开启一个新的线程
    go fmt.Println(2)
    go fmt.Println(3)
    go fmt.Println(4)
    go fmt.Println(5)

    time.Sleep(time.Second)    延迟,防止main()提前运行。main()本身就是goroutine,main()运行完毕之后其goroutine就会结束,并不关心其他goroutine
}

打印
5
4
1
3
2

你可能感兴趣的:(Golang learning 并发 Goroutine)