The Go language gets a method for the number of native logical CPU

  • 2020-05-17 05:40:40
  • OfStack

This example shows how the Go language gets the number of native logical CPU. Share with you for your reference. The specific analysis is as follows:

1 generally speaking, the amount of native logical CPU can be obtained through NumCPU of runtime library, not physical CPU, for example, 1 dual-core CPU with hyper-threading technology would be considered 4 logical CPU

package main
import (
    "runtime"
    "fmt"
)
func main(){
    fmt.Println(runtime.NumCPU())
}

I hope this article has been helpful to you in the programming of Go language.


Related articles: