Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there a difference using std::thread::hardware_concurrency() and boost::thread::hardware_concurrency()?

Tags:

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 
like image 668
derekhh Avatar asked Dec 16 '11 21:12

derekhh


People also ask

What is hardware_ concurrency?

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.

What is Jthread?

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 .


1 Answers

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

like image 103
derekhh Avatar answered Sep 19 '22 13:09

derekhh