diff --git a/tpool/tpool_generic.cc b/tpool/tpool_generic.cc index 8dbd7c94d30..6d2dc22926b 100644 --- a/tpool/tpool_generic.cc +++ b/tpool/tpool_generic.cc @@ -644,7 +644,7 @@ void thread_pool_generic::check_idle(std::chrono::system_clock::time_point now) } /* Switch timer off after 1 minute of idle time */ - if (now - idle_since > max_idle_time) + if (now - idle_since > max_idle_time && m_active_threads.empty()) { idle_since= invalid_timestamp; switch_timer(timer_state_t::OFF); @@ -743,6 +743,12 @@ bool thread_pool_generic::add_thread() if (n_threads >= m_max_threads) return false; + /* + Deadlock danger exists, so monitor pool health + with maintenance timer. + */ + switch_timer(timer_state_t::ON); + if (n_threads >= m_min_threads) { auto now = std::chrono::system_clock::now(); @@ -753,8 +759,6 @@ bool thread_pool_generic::add_thread() Throttle thread creation and wakeup deadlock detection timer, if is it off. */ - switch_timer(timer_state_t::ON); - return false; } } @@ -837,6 +841,7 @@ thread_pool_generic::thread_pool_generic(int min_threads, int max_threads) : // start the timer m_maintenance_timer.set_time(0, (int)m_timer_interval.count()); + m_timer_state = timer_state_t::ON; }