diff --git a/dnn/test/common/utils.h b/dnn/test/common/utils.h index 6cb505dd..3ad6eba0 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 fab09dd9..9b1966e2 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 6e6f8ad0..9edffd43 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