提交 ddba5c96 编写于 作者: M Megvii Engine Team

fix(core): fix nr_threads is zero

GitOrigin-RevId: 0ccbe3c69b5e94afe2068700252c23fca57ac910
上级 67f11788
...@@ -102,7 +102,7 @@ class CpuDispatchChecker final : MegcoreCPUDispatcher { ...@@ -102,7 +102,7 @@ class CpuDispatchChecker final : MegcoreCPUDispatcher {
std::vector<std::thread> m_workers; std::vector<std::thread> m_workers;
#endif #endif
//! Total number of threads, including main thread. //! 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 //! track number of CpuDispatchChecker instances to avoid leaking
......
...@@ -20,6 +20,9 @@ ThreadPool::ThreadPool(size_t threads_num) ...@@ -20,6 +20,9 @@ ThreadPool::ThreadPool(size_t threads_num)
m_main_affinity_flag{false}, m_main_affinity_flag{false},
m_stop{false}, m_stop{false},
m_active{false} { m_active{false} {
if (threads_num < 1) {
m_nr_threads = 1;
}
if (m_nr_threads > 1) { if (m_nr_threads > 1) {
if (m_nr_threads > static_cast<uint32_t>(sys::get_cpu_count())) { if (m_nr_threads > static_cast<uint32_t>(sys::get_cpu_count())) {
mgb_log_debug( mgb_log_debug(
......
...@@ -80,7 +80,7 @@ public: ...@@ -80,7 +80,7 @@ public:
~ThreadPool(); ~ThreadPool();
private: private:
const size_t m_nr_threads = 0; size_t m_nr_threads = 1;
//! Indicate whether the main thread have binding //! Indicate whether the main thread have binding
bool m_main_affinity_flag; bool m_main_affinity_flag;
//! The callback binding the threads to cores //! The callback binding the threads to cores
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册