package main import ( "fmt" "time" ) func hello(i int) { fmt.Println("hello:", i) } func main() { for i := 0; i < 100; i++ { // 开启一个单独的 goroutine 任务 go hello(i) } fmt.Println("main") time.Sleep(1 * time.Millisecond) // main 函数结束时 由 main 函数 启动的 goroutine 任务也随之结束 }