Sobes.tech
Junior — Middle

Kas saaksite selgitada, mida tähendab GOMAXPROCS seadistamine Go keeles?

sobes.tech AI

Vastus AI-lt

In the Go language, the environment variable or parameter GOMAXPROCS determines the maximum number of operating system (OS) threads that can simultaneously execute goroutines.

By default, GOMAXPROCS is equal to the number of logical processors on the machine, allowing efficient utilization of multiprocessor systems.

Setting GOMAXPROCS affects the program's parallelism — how many goroutines can run concurrently on different CPU cores.

Example of setting in code:

import "runtime"

func main() {
    runtime.GOMAXPROCS(4) // limit to 4 threads
    // rest of the code
}

This is useful for resource usage control and performance optimization.