diff --git a/dnn/test/common/utils.h b/dnn/test/common/utils.h index 6cb505ddcb971157d7a313070301d8231903e5b5..3ad6eba0604f08bee37634a7c8d97dbccbd5d184 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 fab09dd90fe1dbaefd78b9af7c3d3b9745b667bc..9b1966e2b9ad889d0fdeb4fb914b9e8481101f6b 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 6e6f8ad0505d5fc79b87cec3a1ae3f680bb4c34a..9edffd437df3035afa48d249fde80b0a2eea72cb 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