mirror of
https://gitee.com/shikong-sk/golang-study
synced 2025-02-23 23:42:15 +08:00
22 lines
334 B
Go
22 lines
334 B
Go
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 任务也随之结束
|
|
}
|