From ddba5c967486d9fb7aa73cf7dbb6bccf327f7763 Mon Sep 17 00:00:00 2001 From: Megvii Engine Team Date: Thu, 29 Jul 2021 14:48:55 +0800 Subject: [PATCH] fix(core): fix nr_threads is zero GitOrigin-RevId: 0ccbe3c69b5e94afe2068700252c23fca57ac910 --- dnn/test/common/utils.h | 2 +- src/core/impl/utils/thread_pool.cpp | 3 +++ src/core/include/megbrain/utils/thread_pool.h | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/dnn/test/common/utils.h b/dnn/test/common/utils.h index 6cb505ddc..3ad6eba06 100644 --- a/dnn/test/common/utils.h +++ b/dnn/test/common/utils.h @@ -102,7 +102,7 @@ class CpuDispatchChecker final : MegcoreCPUDispatcher { std::vector m_workers; #endif //! Total number of threads, including main thread. - size_t m_nr_threads = 0; + size_t m_nr_threads = 1; }; //! track number of CpuDispatchChecker instances to avoid leaking diff --git a/src/core/impl/utils/thread_pool.cpp b/src/core/impl/utils/thread_pool.cpp index fab09dd90..9b1966e2b 100644 --- a/src/core/impl/utils/thread_pool.cpp +++ b/src/core/impl/utils/thread_pool.cpp @@ -20,6 +20,9 @@ ThreadPool::ThreadPool(size_t threads_num) m_main_affinity_flag{false}, m_stop{false}, m_active{false} { + if (threads_num < 1) { + m_nr_threads = 1; + } if (m_nr_threads > 1) { if (m_nr_threads > static_cast(sys::get_cpu_count())) { mgb_log_debug( diff --git a/src/core/include/megbrain/utils/thread_pool.h b/src/core/include/megbrain/utils/thread_pool.h index 6e6f8ad05..9edffd437 100644 --- a/src/core/include/megbrain/utils/thread_pool.h +++ b/src/core/include/megbrain/utils/thread_pool.h @@ -80,7 +80,7 @@ public: ~ThreadPool(); private: - const size_t m_nr_threads = 0; + size_t m_nr_threads = 1; //! Indicate whether the main thread have binding bool m_main_affinity_flag; //! The callback binding the threads to cores -- GitLab