Correctly stop "own thread" in service destructor.

This change fixes the scheduler and win_iocp_io_context destructors so
that they correctly stop the internal thread that was created in the
constructor. This fixes a deadlock that can occur when two threads
concurrently attempt to create the first I/O object associated with a
non-native I/O execution context.
This commit is contained in:
Christopher Kohlhoff 2020-05-30 11:07:23 +10:00
parent 71324d7cbb
commit 50e2c8c88e
2 changed files with 5 additions and 0 deletions

View File

@ -135,6 +135,10 @@ scheduler::~scheduler()
{
if (thread_)
{
mutex::scoped_lock lock(mutex_);
shutdown_ = true;
stop_all_threads(lock);
lock.unlock();
thread_->join();
delete thread_;
}

View File

@ -113,6 +113,7 @@ win_iocp_io_context::~win_iocp_io_context()
{
if (thread_.get())
{
stop();
thread_->join();
thread_.reset();
}