diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-09-20 07:48:49 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-20 07:48:49 -0700 |
commit | cfd070c4e0eed92737794dfcf7620393fcf25537 (patch) | |
tree | b1a13a692f4b0e6bea11aa973c36b0f81641c6da /src/mbgl/actor/thread_pool.cpp | |
parent | c3a583cdd59c4ed8e67468caa7d2af74791c01b7 (diff) | |
download | qtlocation-mapboxgl-cfd070c4e0eed92737794dfcf7620393fcf25537.tar.gz |
[core] Fix ThreadPool race condition (#6388)
Diffstat (limited to 'src/mbgl/actor/thread_pool.cpp')
-rw-r--r-- | src/mbgl/actor/thread_pool.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/mbgl/actor/thread_pool.cpp b/src/mbgl/actor/thread_pool.cpp index 89ca1b72f0..2995ed26ad 100644 --- a/src/mbgl/actor/thread_pool.cpp +++ b/src/mbgl/actor/thread_pool.cpp @@ -11,10 +11,10 @@ ThreadPool::ThreadPool(std::size_t count) { std::unique_lock<std::mutex> lock(mutex); cv.wait(lock, [this] { - return !queue.empty() || terminate.load(); + return !queue.empty() || terminate; }); - if (terminate.load()) { + if (terminate) { return; } @@ -31,7 +31,11 @@ ThreadPool::ThreadPool(std::size_t count) { } ThreadPool::~ThreadPool() { - terminate.store(true); + { + std::lock_guard<std::mutex> lock(mutex); + terminate = true; + } + cv.notify_all(); for (auto& thread : threads) { @@ -40,8 +44,11 @@ ThreadPool::~ThreadPool() { } void ThreadPool::schedule(std::weak_ptr<Mailbox> mailbox) { - std::lock_guard<std::mutex> lock(mutex); - queue.push(mailbox); + { + std::lock_guard<std::mutex> lock(mutex); + queue.push(mailbox); + } + cv.notify_one(); } |