thread :: hardware_concurrency()检查返回零值 [英] thread::hardware_concurrency() checking returns zero value

查看:113
本文介绍了thread :: hardware_concurrency()检查返回零值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用64位RHEL 6,并在四核处理器上的虚拟机上运行.我编写了以下程序来检查硬件可以处理的线程数.

I'm using RHEL 6 64-bit and run on Virtual Machine on quad-core processors. I wrote the following program to examine the number of threads the hardware can handle.

#include <thread>
#include <iostream>

using namespace std;

int main()
{
    cout << thread::hardware_concurrency() << endl;
    return 0;
}

结果始终为零,为什么呢?

The result is always zero, what is the reason of such result?

推荐答案

来自 cppreference :

返回受支持的并发线程数 执行.该值应仅视为提示.

Returns the number of concurrent threads supported by the implementation. The value should be considered only a hint.

还有:

返回值

支持的并发线程数.如果值不好 已定义或不可计算,则返回"0".

number of concurrent threads supported. If the value is not well defined or not computable, returns ​0​.

所以thread::hardware_concurrency()不必给您任何准确的信息.旁观者也认为准确".如果我有两个支持超线程的内核,hardware_concurrency应该返回2还是4?

so thread::hardware_concurrency() doesn't have to give you anything accurate.
"accurate" is also in the eyes of the beholder. If I have two cores which support hyper-threading, should hardware_concurrency return 2 or 4?

这篇关于thread :: hardware_concurrency()检查返回零值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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