std::thread::hardware_concurrency

Hi, i've just tried to output
std::thread::hardware_concurrency on my laptop under different Oses and was rather suprised.

and if cygwin with gcc 5.4 returns '1' i wasn't suprised as multithreading under cygwin it is a big question. But when debian x64 returns same '1' i decided to ask there.

My laptop is K52DR-A1 which equipped with AMD Phenom II Triple-Core N830. DEbian sees all three cores:


cat /proc/stat
cpu  92509 83 28042 610157 7362 79 1201 0 0 0
cpu0 30568 30 9090 205111 2365 2 182 0 0 0
cpu1 31567 23 8696 204539 2130 8 270 0 0 0
cpu2 30373 29 10256 200506 2866 67 748 0 0 0
intr 3895984 527736 2513 0 0 0 0 0 1 1 0 0 0 330507 0 0 0 196479 28 55 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61604 158 148641 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ctxt 6019104
btime 1482057841
processes 5337
procs_running 2
procs_blocked 0
softirq 1683822 7 500272 304 289 60692 0 241881 327822 2172 550383


meanwhile version of gcc under debian is 4.9.2
Last edited on
found error in program. Output should be std::thread::hardware_concurrency() instead std::thread::hardware_concurrency. And only clang notices that. g++ said nothing :(
> g++ said nothing :(

When compiling with the GNU compiler,
explicitly demand conformance to standard C++ (-std=c++14 -pedantic-errors)
and enable all warnings (-Wall -Wextra).

clang++
------

main.cpp:6:18: warning: address of function 'std::thread::hardware_concurrency' will always evaluate to 'true' [-Wpointer-bool-conversion]
    std::cout << std::thread::hardware_concurrency << '\n' ;
              ~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:6:18: note: prefix with the address-of operator to silence this warning
    std::cout << std::thread::hardware_concurrency << '\n' ;
                 ^
                 &
1 warning generated.


g++
----

main.cpp: In function 'int main()':
main.cpp:6:31: warning: the address of 'static unsigned int std::thread::hardware_concurrency()' will always evaluate as 'true' [-Waddress]
     std::cout << std::thread::hardware_concurrency << '\n' ;
                               ^~~~~~~~~~~~~~~~~~~~

http://coliru.stacked-crooked.com/a/95a3b46f48379bc9
Last edited on
meanwhile version of gcc under debian is 4.9.2


The latest version of g++ is 6.2.1, why don't you upgrade? Then you can use all of C++14 and some of C++17 as well.
Topic archived. No new replies allowed.