Skip to content

Commit 708445c

Browse files
committed
Fix thread_poll joinable should be atomic
1 parent 231cb29 commit 708445c

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

asio/include/asio/impl/thread_pool.ipp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ void thread_pool::attach()
125125

126126
void thread_pool::join()
127127
{
128-
if (joinable_)
128+
bool expected = true;
129+
if (joinable_.compare_exchange_strong(expected, false))
129130
{
130-
joinable_ = false;
131131
scheduler_.work_finished();
132132
threads_.join();
133133
}

asio/include/asio/thread_pool.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ class thread_pool
229229
detail::atomic_count num_threads_;
230230

231231
// Whether a join call will have any effect.
232-
bool joinable_;
232+
std::atomic<bool> joinable_;
233233
};
234234

235235
/// Executor implementation type used to submit functions to a thread pool.

0 commit comments

Comments
 (0)