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

fix(core): fix nr_threads is zero

GitOrigin-RevId: 0ccbe3c69b5e94afe2068700252c23fca57ac910
上级 67f11788
......@@ -102,7 +102,7 @@ class CpuDispatchChecker final : MegcoreCPUDispatcher {
std::vector<std::thread> 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
......
......@@ -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<uint32_t>(sys::get_cpu_count())) {
mgb_log_debug(
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册