[llvm-branch-commits] [llvm] 2c9cb89 - [Support] Fix race in threading test, found by TSan

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Jan 27 05:48:17 PST 2020


Author: Sam McCall
Date: 2020-01-27T14:44:44+01:00
New Revision: 2c9cb89d0d00dc8669410a7d57ada11c5f7f8409

URL: https://github.com/llvm/llvm-project/commit/2c9cb89d0d00dc8669410a7d57ada11c5f7f8409
DIFF: https://github.com/llvm/llvm-project/commit/2c9cb89d0d00dc8669410a7d57ada11c5f7f8409.diff

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

(cherry picked from commit 18e6a65bae93a7bf0e718415b394fe4b0f09221e)

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-branch-commits mailing list