Commit 86407a59 authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

MDEV-16264 - Fix assertion `m_queue.empty() && !m_tasks_running' in tpool::task_group destructor

This particular assertion happened when shutting down Innodb IO.IO shutdown properly waits for all IOs to finish


However there is a race condition -
right after releasing last IO slot and before decrementing task count
in group, pending_io_count will be 0, but tasks_running will be 1,
leading to assertion.

The fix is to make task_group destructor to wait for last running task
to finish.
parent 38c2c16c
...@@ -20,6 +20,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 - 1301 USA*/ ...@@ -20,6 +20,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 - 1301 USA*/
#include <tpool_structs.h> #include <tpool_structs.h>
#include <thread> #include <thread>
#include <assert.h> #include <assert.h>
#ifndef _WIN32
#include <unistd.h> // usleep
#endif
namespace tpool namespace tpool
{ {
task_group::task_group(unsigned int max_concurrency) : task_group::task_group(unsigned int max_concurrency) :
...@@ -79,6 +82,18 @@ namespace tpool ...@@ -79,6 +82,18 @@ namespace tpool
task_group::~task_group() task_group::~task_group()
{ {
assert(m_queue.empty() && !m_tasks_running); std::unique_lock<std::mutex> lk(m_mtx);
assert(m_queue.empty());
while (m_tasks_running)
{
lk.unlock();
#ifndef _WIN32
usleep(1000);
#else
Sleep(1);
#endif
lk.lock();
}
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment