[PATCH] D38481: Use sched_getaffinity instead of std::thread::hardware_concurrency when available
Rui Ueyama via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 2 17:45:34 PDT 2017
ruiu added inline comments.
================
Comment at: include/llvm/Support/ThreadPool.h:42
+ /// Construct a pool with the number of threads found by
+ /// get_available_threads().
ThreadPool();
----------------
hardware_concurrency()
================
Comment at: lib/Support/Threading.cpp:82
+#endif
+ return std::thread::hardware_concurrency();
+}
----------------
AFAIK std::thread::hardware_concurrency() is allowed to return 0 if it doesn't know anything about hardware concurrency. I don't know if there's actually such system that the function could return 0, but it is better to not rely on an undefined behavior. I'd explicitly check if std::thread::hardware_concurrency returns 0 and if that's the case, return 1.
https://reviews.llvm.org/D38481
More information about the llvm-commits
mailing list