Golang 运行根据主机的CPU个数,并发运行。
package main import ( "fmt" "runtime" ) func main() { fmt.Println(runtime.NumCPU()) // runtime.NumCPU() 读取CPU数量 runtime.GOMAXPROCS(runtime.NumCPU()) }
Golang 运行根据主机的CPU个数,并发运行。
package main import ( "fmt" "runtime" ) func main() { fmt.Println(runtime.NumCPU()) // runtime.NumCPU() 读取CPU数量 runtime.GOMAXPROCS(runtime.NumCPU()) }