summaryrefslogtreecommitdiff
path: root/src/thread_pool.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/thread_pool.cc')
-rw-r--r--src/thread_pool.cc14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/thread_pool.cc b/src/thread_pool.cc
index fa0cf794c4..f3319e2d40 100644
--- a/src/thread_pool.cc
+++ b/src/thread_pool.cc
@@ -69,11 +69,15 @@ ThreadPool::ThreadPool(size_t num_threads)
}
ThreadPool::~ThreadPool() {
- // Tell any remaining workers to shut down.
- shutting_down_ = true;
- android_memory_barrier();
- // Broadcast to everyone waiting.
- task_queue_condition_.Broadcast(Thread::Current());
+ {
+ Thread* self = Thread::Current();
+ MutexLock mu(self, task_queue_lock_);
+ // Tell any remaining workers to shut down.
+ shutting_down_ = true;
+ android_memory_barrier();
+ // Broadcast to everyone waiting.
+ task_queue_condition_.Broadcast(self);
+ }
// Wait for the threads to finish.
STLDeleteElements(&threads_);
}