[libcxx-commits] [libcxx] [libc++] Fixed get count threads multi-CPU system with NUMA architecture (#72267) (PR #72270)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Nov 15 08:33:05 PST 2023
================
@@ -81,9 +81,58 @@ thread::hardware_concurrency() noexcept
return 0;
return static_cast<unsigned>(result);
#elif defined(_LIBCPP_WIN32API)
- SYSTEM_INFO info;
- GetSystemInfo(&info);
- return info.dwNumberOfProcessors;
+ // This implementation supports both conventional single-cpu PC configurations
+ // and multi-cpu system on NUMA (Non-uniform_memory_access) architecture
+ DWORD length = 0;
+ unsigned concurrency = 0;
----------------
ldionne wrote:
You could simplify like this:
```
const auto single_cpu_concurrency = []() noexcept -> unsigned int {
SYSTEM_INFO info;
GetSystemInfo(&info);
return info.dwNumberOfProcessors;
};
if (GetLogicalProcessorInformationEx(RelationAll, nullptr, &length) != FALSE)
return single_cpu_concurrency();
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
return single_cpu_concurrency();
[...]
DWORD i = 0;
unsigned int concurrency = 0;
while (i < length) {
[...]
}
return concurrency;
```
In other words, there is no reason to pass `concurrency` by reference to the lambda, it just makes the control flow more complicated to follow.
https://github.com/llvm/llvm-project/pull/72270
More information about the libcxx-commits
mailing list