[PATCH] D18811: Fix a race condition in support library ThreadPool

Jason Henline via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 6 15:53:06 PDT 2016


jhen updated this revision to Diff 52862.
jhen added a comment.

- Simplify the change to one line


http://reviews.llvm.org/D18811

Files:
  lib/Support/ThreadPool.cpp

Index: lib/Support/ThreadPool.cpp
===================================================================
--- lib/Support/ThreadPool.cpp
+++ lib/Support/ThreadPool.cpp
@@ -75,8 +75,11 @@
 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) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18811.52862.patch
Type: text/x-patch
Size: 786 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160406/9a598ae4/attachment.bin>


More information about the llvm-commits mailing list