aboutsummaryrefslogtreecommitdiff
path: root/lib/Support/ThreadPool.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2016-07-23 20:41:05 +0000
committerDimitry Andric <dim@FreeBSD.org>2016-07-23 20:41:05 +0000
commit01095a5d43bbfde13731688ddcf6048ebb8b7721 (patch)
tree4def12e759965de927d963ac65840d663ef9d1ea /lib/Support/ThreadPool.cpp
parentf0f4822ed4b66e3579e92a89f368f8fb860e218e (diff)
Notes
Diffstat (limited to 'lib/Support/ThreadPool.cpp')
-rw-r--r--lib/Support/ThreadPool.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/Support/ThreadPool.cpp b/lib/Support/ThreadPool.cpp
index d4dcb2ee96df..db03a4d6240d 100644
--- a/lib/Support/ThreadPool.cpp
+++ b/lib/Support/ThreadPool.cpp
@@ -75,8 +75,11 @@ ThreadPool::ThreadPool(unsigned ThreadCount)
void ThreadPool::wait() {
// Wait for all threads to complete and the queue to be empty
std::unique_lock<std::mutex> LockGuard(CompletionLock);
+ // The order of the checks for ActiveThreads and Tasks.empty() matters because
+ // any active threads might be modifying the Tasks queue, and this would be a
+ // race.
CompletionCondition.wait(LockGuard,
- [&] { return Tasks.empty() && !ActiveThreads; });
+ [&] { return !ActiveThreads && Tasks.empty(); });
}
std::shared_future<ThreadPool::VoidTy> ThreadPool::asyncImpl(TaskTy Task) {