| @@ -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) | |||||
| 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: | |||||
| ~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 | ||||