[libcxx] r185451 - Windows support in thread::hardware_concurrency.

Howard Hinnant hhinnant at apple.com
Wed Jul 3 08:05:58 PDT 2013

On Jul 3, 2013, at 12:35 AM, Chandler Carruth <chandlerc at google.com> wrote:

> On Tue, Jul 2, 2013 at 9:10 PM, Nico Rieck <nico.rieck at gmail.com> wrote:
> On 02.07.2013 23:55, Óscar Fuentes wrote:
> Nico and Howard,
> Nico Rieck <nico.rieck at gmail.com> writes:
> On 02.07.2013 19:53, Howard Hinnant wrote:
> +#elif defined(_WIN32)
> +    SYSTEM_INFO info;
> +    GetSystemInfo(&info);
> +    return info.dwNumberOfProcessors;
>    #else  // defined(CTL_HW) && defined(HW_NCPU)
> I'm not that familiar with the implementation for the other platforms,
> but this snippet returns the number of logical processors. In my local
> Windows port I use the number of cores, as I think that's more
> appropriate. This is also what MSVCRT does on Windows.
> As per my interpretation of the standard, returning the number of
> logical processors is the right thing.
> I checked VS2013 on a hyperthreaded machine and
> std::thread::hardware_concurrency does just that. Same for
> boost::thread::hardware_concurrency.
> Did they change that? VS2012 uses GetLogicalProcessorInformation/Ex for Vista/7+, and GetSystemInfo below. Boost seems to use the latter.
> And if people use this to (for example) determine the amount of threads to spawn, number of cores makes more sense to me.
> No, just the opposite. You want to spawn a number of software threads based on how many hardware threads your system can handle. For hyperthreaded systems each core can handle two hardware threads so that's how many should be spawned.

Agreed this is the intent.

On Mac OS X, using an iMac equipped with a Core i5, this program:

#include <iostream>
#include <thread>

    std::cout << std::thread::hardware_concurrency() << '\n';




More information about the cfe-commits mailing list