gitee.com/quant1x/gox@v1.21.2/runtime/cpus.go (about)

     1  package runtime
     2  
     3  import "runtime"
     4  
     5  // GoMaxProcs 设置CPU核数
     6  func GoMaxProcs(n ...int) {
     7  	numCPU := runtime.NumCPU() / 2
     8  	if len(n) > 0 && n[0] > 0 {
     9  		numCPU = n[0]
    10  	}
    11  	runtime.GOMAXPROCS(numCPU)
    12  }