thread::hardware_concurrency() checking returns zero value

我怕爱的太早我们不能终老 提交于 2020-01-07 04:55:11

问题


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?


回答1:


from cppreference:

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

and also :

Return value

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

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?



来源:https://stackoverflow.com/questions/37000731/threadhardware-concurrency-checking-returns-zero-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!