标签:for main roc class height cpu package 协程 ima
package main import ( "fmt" "strconv" "time" ) func test() { for i := 1; i <= 10; i++ { fmt.Println("tesst,hello,world " + strconv.Itoa(i)) time.Sleep(time.Second) } } func main() { go test() // 开启了一个协程 for i := 1; i <= 10; i++ { fmt.Println(" main,hello,golang" + strconv.Itoa(i)) time.Sleep(time.Second) } }
package main import ( "runtime" "fmt" ) func main() { cpuNum := runtime.NumCPU() fmt.Println("cpuNum=", cpuNum) //可以自己设置使用多个cpu runtime.GOMAXPROCS(cpuNum - 1) fmt.Println("ok") }
标签:for main roc class height cpu package 协程 ima
原文地址:https://www.cnblogs.com/yzg-14/p/12235329.html