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

Justin Lebar via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 6 16:52:01 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL265618: Fix a race condition in support library ThreadPool. (authored by jlebar).

Changed prior to commit:
  http://reviews.llvm.org/D18811?vs=52862&id=52872#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D18811

Files:
  llvm/trunk/lib/Support/ThreadPool.cpp

Index: llvm/trunk/lib/Support/ThreadPool.cpp
===================================================================
--- llvm/trunk/lib/Support/ThreadPool.cpp
+++ llvm/trunk/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.52872.patch
Type: text/x-patch
Size: 819 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160406/cccba26e/attachment-0001.bin>


More information about the llvm-commits mailing list