From 244abdbfa27421ddaf120ac26fff161d393f98c3 Mon Sep 17 00:00:00 2001 From: t-horikawa Date: Tue, 13 Aug 2024 11:04:26 +0900 Subject: [PATCH] cache std::thread::hardware_concurrency() result at start up --- include/destroy_manager.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/destroy_manager.h b/include/destroy_manager.h index 741bcaa..a98be36 100644 --- a/include/destroy_manager.h +++ b/include/destroy_manager.h @@ -14,7 +14,7 @@ class destroy_manager { std::size_t expected{ destroy_threads_num_.load(std::memory_order_acquire)}; for (;;) { - if (expected >= std::thread::hardware_concurrency()) { + if (expected >= hardware_concurrency_) { return false; } std::size_t desired = expected + 1; @@ -34,6 +34,7 @@ class destroy_manager { private: static inline std::atomic destroy_threads_num_{0}; // NOLINT + static inline std::size_t hardware_concurrency_{std::thread::hardware_concurrency()}; // NOLINT }; } // namespace yakushima