I am new to Google Go (Golang). My question is related to this post What exactly does runtime.Gosched do?. The structure of code is as copied below. My question, is that whe
The number of cores can be inquired by http://golang.org/pkg/runtime/#NumCPU.
The documentation says: "NumCPU returns the number of logical CPUs on the local machine."
The largest number of logical CPUs the process can be running on at a given time is no more than the minimum of runtime.GOMAXPROCS(0) and runtime.NumCPU().
func MaxParallelism() int {
maxProcs := runtime.GOMAXPROCS(0)
numCPU := runtime.NumCPU()
if maxProcs < numCPU {
return maxProcs
}
return numCPU
}