问题
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