Standard library / runtime

runtime.GOMAXPROCS()

Sets the maximum number of CPUs executing Go code simultaneously and returns the previous setting. Nonpositive input queries without changing it. Restore settings in experiments. Expected stdout: '1\n'.

Formal Syntax & Structure

go syntaxgo
func GOMAXPROCS(n int) int

Parameters & Attributes

NameTypeDescription
nintRequested CPU parallelism; zero or a negative value leaves the setting unchanged.

Return Value

int

Previous CPU parallelism setting.

Working Example

Example Snippetgo
package main
import (  "fmt"  "runtime")
func main() {  old := runtime.GOMAXPROCS(1)  defer runtime.GOMAXPROCS(old)  fmt.Println(runtime.GOMAXPROCS(0))}
Go Reference