The description of the problem itself is pretty simple. I'm testing the differences of std::thread library in C++11 and boost::thread library.
The output of these:
#include <iostream> #include <thread> #include <boost/thread.hpp> int main() { std::cout << std::thread::hardware_concurrency() << std::endl; std::cout << boost::thread::hardware_concurrency() << std::endl; return 0; }
gives me different results:
0 4
Why is that?
PS: The version of the gcc package is 4.6.2-1.fc16 (x86_64). I'm using
g++ test.cc -Wall -std=c++0x -lboost_thread-mt -lpthread
Thread hardware_concurrency() function in C++ This function returns the number of concurrent threads supported by the available hardware implementation. This value might not always be accurate.
jthread fixes this; it joins on destruction by default (hence the name: "joining thread"). It also supports a mechanism to ask a thread to halt execution, though there is no enforcement of this (aka: you can't make another thread stop executing). At present, there is no plan to deprecate std::thread .
After reviewing /usr/include/c++/4.6.2/thread
it can be seen that the implementation is actually:
// Returns a value that hints at the number of hardware thread contexts. static unsigned int hardware_concurrency() { return 0; }
So problem solved. It's just another feature that hasn't been implemented in gcc 4.6.2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With