Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: std::thread::hardware_concurrency() returns 0



Permlink Replies: 4 - Last Post: Jan 24, 2018 6:46 AM Last Post By: Ted Lyngmo
Ted Lyngmo

Posts: 117
Registered: 10/3/06
std::thread::hardware_concurrency() returns 0
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 23, 2018 3:33 AM
Hi!

I've started using the standard <thread> lib and compiled my program on a few platforms with different compilers and all but C++ Builder (clang) manages to return the correct number of threads supported by hardware by using
std::thread::hardware_concurrency() on all the computers I've tested it on. I know std::thread::hardware_concurrency() is only supposed to give you a hint and return 0 if it wasn't able to figure it out but since it manages to figure out the correct number in VS2017 I can't help but wondering if the std::thread::hardware_concurrency() implementation is broken in C++ Builder?

Has anyone else used it successfully?

Br,
Ted
Vladimir Zhuchko

Posts: 116
Registered: 1/22/98
Re: std::thread::hardware_concurrency() returns 0
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 23, 2018 7:11 AM   in response to: Ted Lyngmo in response to: Ted Lyngmo
Ted Lyngmo wrote:
Hi!

I've started using the standard <thread> lib and compiled my program on a few platforms with different compilers and all but C++ Builder (clang) manages to return the correct number of threads supported by hardware by using
std::thread::hardware_concurrency() on all the computers I've tested it on. I know std::thread::hardware_concurrency() is only supposed to give you a hint and return 0 if it wasn't able to figure it out but since it manages to figure out the correct number in VS2017 I can't help but wondering if the std::thread::hardware_concurrency() implementation is broken in C++ Builder?

Has anyone else used it successfully?

Br,
Ted
Yes, I have real number of threads using:
int cores_number = boost::thread::hardware_concurrency();
My application was compiled for Win64 (clang)
--
With best regards
Dr. Vladimir Zhuchko
Ted Lyngmo

Posts: 117
Registered: 10/3/06
Re: std::thread::hardware_concurrency() returns 0
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 23, 2018 8:56 AM   in response to: Vladimir Zhuchko in response to: Vladimir Zhuchko
Vladimir Zhuchko wrote:
Ted Lyngmo wrote:
I can't help but wondering if the std::thread::hardware_concurrency() implementation is broken in C++ Builder?
Has anyone else used it successfully?
Yes, I have real number of threads using:
int cores_number = boost::thread::hardware_concurrency();
My application was compiled for Win64 (clang)

I see - but that's not the implementation used in C++ Builder I think? What about if you try std::thread::hardware_concurrency() ?

My program was compiled for 32 bit but gives 0 on both 32 and 64 bit machines.
If I use std::thread::hardware_concurrency() in Visual Studio (or gcc etc) it'll give me the expected values returned, depending on where I run my program.

Br,
Ted
Vladimir Zhuchko

Posts: 116
Registered: 1/22/98
Re: std::thread::hardware_concurrency() returns 0
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 23, 2018 11:06 PM   in response to: Ted Lyngmo in response to: Ted Lyngmo
Ted Lyngmo wrote:
Vladimir Zhuchko wrote:
Ted Lyngmo wrote:
I can't help but wondering if the std::thread::hardware_concurrency() implementation is broken in C++ Builder?
Has anyone else used it successfully?
Yes, I have real number of threads using:
int cores_number = boost::thread::hardware_concurrency();
My application was compiled for Win64 (clang)

I see - but that's not the implementation used in C++ Builder I think? What about if you try std::thread::hardware_concurrency() ?

My program was compiled for 32 bit but gives 0 on both 32 and 64 bit machines.
If I use std::thread::hardware_concurrency() in Visual Studio (or gcc etc) it'll give me the expected values returned, depending on where I run my program.

Br,
Ted

Yes, with std this value is equal to zero, but with boost works fine.
I am using Cbuilder-Tokyo for my programs.
I think you can put this issue to the JIRA

--
With best regards
Dr. Vladimir Zhuchko

Edited by: Vladimir Zhuchko on Jan 24, 2018 3:16 AM
Ted Lyngmo

Posts: 117
Registered: 10/3/06
Re: std::thread::hardware_concurrency() returns 0
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 24, 2018 6:46 AM   in response to: Vladimir Zhuchko in response to: Vladimir Zhuchko
Vladimir Zhuchko wrote:
Ted Lyngmo wrote:
What about if you try std::thread::hardware_concurrency() ?

Yes, with std this value is equal to zero,
I am using Cbuilder-Tokyo for my programs.

Me too.

I think you can put this issue to the JIRA

Good idea: https://quality.embarcadero.com/browse/RSP-19821

Br,
Ted
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02