diff --git a/asio/include/asio/impl/thread_pool.ipp b/asio/include/asio/impl/thread_pool.ipp index e39f07f81c..2439505f6c 100644 --- a/asio/include/asio/impl/thread_pool.ipp +++ b/asio/include/asio/impl/thread_pool.ipp @@ -125,9 +125,9 @@ void thread_pool::attach() void thread_pool::join() { - if (joinable_) + bool expected = true; + if (joinable_.compare_exchange_strong(expected, false)) { - joinable_ = false; scheduler_.work_finished(); threads_.join(); } diff --git a/asio/include/asio/thread_pool.hpp b/asio/include/asio/thread_pool.hpp index b359acd377..ebedb7fb9b 100644 --- a/asio/include/asio/thread_pool.hpp +++ b/asio/include/asio/thread_pool.hpp @@ -229,7 +229,7 @@ class thread_pool detail::atomic_count num_threads_; // Whether a join call will have any effect. - bool joinable_; + std::atomic joinable_; }; /// Executor implementation type used to submit functions to a thread pool.