mirror of
https://github.com/MariaDB/server.git
synced 2025-01-27 01:04:19 +01:00
MDEV-21551 Fix race condition in thread_pool_generic::wait_begin()
While waiting for mutex, thread_pool_generic::wait_begin(), current task can be marked long-running. This is done by periodic mantainence task, that runs in parallel. Fix to recheck is_long_task() after the mutex acquisition.
This commit is contained in:
parent
700e010309
commit
fde1589f9b
1 changed files with 14 additions and 2 deletions
|
@ -454,9 +454,12 @@ bool thread_pool_generic::get_task(worker_data *thread_var, task **t)
|
|||
{
|
||||
std::unique_lock<std::mutex> lk(m_mtx);
|
||||
|
||||
if (thread_var->is_long_task() && m_long_tasks_count)
|
||||
if (thread_var->is_long_task())
|
||||
{
|
||||
DBUG_ASSERT(m_long_tasks_count);
|
||||
m_long_tasks_count--;
|
||||
|
||||
}
|
||||
DBUG_ASSERT(!thread_var->is_waiting());
|
||||
thread_var->m_state = worker_data::NONE;
|
||||
|
||||
while (m_task_queue.empty())
|
||||
|
@ -747,6 +750,15 @@ void thread_pool_generic::wait_begin()
|
|||
if (!tls_worker_data || tls_worker_data->is_long_task())
|
||||
return;
|
||||
std::unique_lock<std::mutex> lk(m_mtx);
|
||||
if(tls_worker_data->is_long_task())
|
||||
{
|
||||
/*
|
||||
Current task flag could have become "long-running"
|
||||
while waiting for the lock, thus recheck.
|
||||
*/
|
||||
return;
|
||||
}
|
||||
DBUG_ASSERT(!tls_worker_data->is_waiting());
|
||||
tls_worker_data->m_state |= worker_data::WAITING;
|
||||
m_waiting_task_count++;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue