什么是GOMAXPROCS默认值 [英] what is the GOMAXPROCS default value

查看:331
本文介绍了什么是GOMAXPROCS默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当没有设置相同名称的环境变量时,是否保证GOMAXPROCS设置为1?

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

此代码显示值:

package main

import (
    "runtime"
    "fmt"
)

func getGOMAXPROCS() int {
    return runtime.GOMAXPROCS(0)
}

func main() {
    fmt.Printf("GOMAXPROCS is %d\n", getGOMAXPROCS())
}

和像这样运行它:

and running it like this:

$ GOMAXPROCS= go run max.go 
GOMAXPROCS is 1

表明在这种情况下它是1,但我正在寻找一些确认信息。

shows that it is 1 in this case, but I am looking for some confirmation here.

推荐答案

不,不知道默认是什么;即使所有已知的实现都使用值'1'。如果您的代码在没有环境变量的情况下需要特定的默认值,那么您应该将其设置为代码。 另外

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设置可同时执行的最大CPU数并返回以前的设置。如果n < 1,它不会改变当前设置。本地机器上的逻辑CPU数量可以通过NumCPU查询。 当调度程序改进时,此调用将消失。

(强调我的)

这篇关于什么是GOMAXPROCS默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆