March 2020
Intermediate to advanced
406 pages
8h 39m
English
The NumCPU function returns the usable number of logical CPUs of the current process. When the binary is invoked, the runtime validates the number of CPUs that are available at startup. A simple example of this can be found in the following code snippet:
package mainimport ( "fmt" "runtime")func main() { fmt.Println("Number of CPUs Available: ", runtime.NumCPU())}
Now, we can see the number of CPUs currently available to the process. In my case, this value ended up being 4:

With this, we can see that my computer has 4 CPUs available for use.
Read now
Unlock full access