[llvm] 18e6a65 - [Support] Fix race in threading test, found by TSan

Sam McCall via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 25 06:22:27 PST 2020


Author: Sam McCall
Date: 2020-01-25T15:22:12+01:00
New Revision: 18e6a65bae93a7bf0e718415b394fe4b0f09221e

URL: https://github.com/llvm/llvm-project/commit/18e6a65bae93a7bf0e718415b394fe4b0f09221e
DIFF: https://github.com/llvm/llvm-project/commit/18e6a65bae93a7bf0e718415b394fe4b0f09221e.diff

LOG: [Support] Fix race in threading test, found by TSan

Added: 
    

Modified: 
    llvm/unittests/Support/Threading.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/unittests/Support/Threading.cpp b/llvm/unittests/Support/Threading.cpp
index 21baa55ef443..183c9aa7d71c 100644
--- a/llvm/unittests/Support/Threading.cpp
+++ b/llvm/unittests/Support/Threading.cpp
@@ -32,8 +32,10 @@ class Notification {
     {
       std::lock_guard<std::mutex> Lock(M);
       Notified = true;
+      // Broadcast with the lock held, so it's safe to destroy the Notification
+      // after wait() returns.
+      CV.notify_all();
     }
-    CV.notify_all();
   }
 
   bool wait() {


        


More information about the llvm-commits mailing list