Skip to content

Commit f6e9600

Browse files
committed
MDEV-33840 tpool- switch to longer maintainence timer interval, if pool is idle
Previous solution, that would entirely switch timer off, turned out to be deadlock prone. This patch fixed previous attempt to switch between long/short interval periods in MDEV-24295. Now, initial state of the timer is fixed (it is ON). Also, avoid switching timer to longer periods if there is any activity in the pool.
1 parent 2ba79ab commit f6e9600

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

tpool/tpool_generic.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ void thread_pool_generic::check_idle(std::chrono::system_clock::time_point now)
644644
}
645645

646646
/* Switch timer off after 1 minute of idle time */
647-
if (now - idle_since > max_idle_time)
647+
if (now - idle_since > max_idle_time && m_active_threads.empty())
648648
{
649649
idle_since= invalid_timestamp;
650650
switch_timer(timer_state_t::OFF);
@@ -743,6 +743,12 @@ bool thread_pool_generic::add_thread()
743743
if (n_threads >= m_max_threads)
744744
return false;
745745

746+
/*
747+
Deadlock danger exists, so monitor pool health
748+
with maintenance timer.
749+
*/
750+
switch_timer(timer_state_t::ON);
751+
746752
if (n_threads >= m_min_threads)
747753
{
748754
auto now = std::chrono::system_clock::now();
@@ -753,8 +759,6 @@ bool thread_pool_generic::add_thread()
753759
Throttle thread creation and wakeup deadlock detection timer,
754760
if is it off.
755761
*/
756-
switch_timer(timer_state_t::ON);
757-
758762
return false;
759763
}
760764
}
@@ -837,6 +841,7 @@ thread_pool_generic::thread_pool_generic(int min_threads, int max_threads) :
837841

838842
// start the timer
839843
m_maintenance_timer.set_time(0, (int)m_timer_interval.count());
844+
m_timer_state = timer_state_t::ON;
840845
}
841846

842847

0 commit comments

Comments
 (0)