what is the GOMAXPROCS default value

后端 未结 3 1408
夕颜
夕颜 2021-02-01 02:01

Is it guaranteed that GOMAXPROCS is set to 1 when the environment variable of the same name is not set?

This code shows the value:

package main

import (         


        
3条回答
  •  别那么骄傲
    2021-02-01 02:35

    UPDATE 2018: By default, Go programs run with GOMAXPROCS set to the number of cores available; in prior releases it defaulted to 1.

    Starting from Go 1.5, the default value is the number of cores. You only need to explicitly set it if you are not okay with this in newer Go versions.


    No, there's no guarantee about what the default is; even though all known implementations use the value '1'. If your code, in absence of the environment variable, requires a specific default value then you should set it in code. Additionally:

    GOMAXPROCS sets the maximum number of CPUs that can be executing simultaneously and returns the previous setting. If n < 1, it does not change the current setting. The number of logical CPUs on the local machine can be queried with NumCPU. This call will go away when the scheduler improves.

    (Emphasis mine)

提交回复
热议问题