Tuesday, June 21, 2011

A bit of C++0x std::thread get recommended number of threads for your system

In c++x0 we have this cool function that will tell you recommended number of concurrent threads for your system:

#include <thread>
#include <iostream>

int main()
{
    std::cout << "Recommended number of concurrent threads for your system (hint): "                      
        << std::thread::hardware_concurrency()
        << std::endl;

    return 0;
}

Unfortunately it returns zero for my home computer :)

P.S. Here is more info about std::thread...