package main
import (
"fmt"
"runtime"
"time"
)
var i int
func calc(i1 int) {
for ;i < 10; i++ { // 死循环,不会自己结束的
//i ++
fmt.Printf("全局i:%d >>> 局部i1:%d go 杀杀杀 calc\n", i,i1)
if i >= 10{
fmt.Printf("i=%d",i)
}
}
fmt.Println("结束for 循环go calc i:", i,i1)
}
func main() {
cpu := runtime.NumCPU()
fmt.Println("cpu:", cpu)
runtime.GOMAXPROCS(2) //指定运行的cpu个数, go 1.8 之后,默认是全部cpu运行
//time.Sleep(time.Second *20)
fmt.Println("start i:", i)
for i1 := 0; i1 < 10; i1++ {
go calc(i1)
fmt.Printf("循环%d\n", i1)
//calc()
//i ++
}
time.Sleep(time.Second * 30)
fmt.Println("i:", i)
}