[clang-tools-extra] 6ac3fd9 - [clangd] Fix race in Global CDB shutdown

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 2 06:24:34 PST 2021


Author: Sam McCall
Date: 2021-02-02T15:24:14+01:00
New Revision: 6ac3fd9706047304c52a678884122a3a6bc55432

URL: https://github.com/llvm/llvm-project/commit/6ac3fd9706047304c52a678884122a3a6bc55432
DIFF: https://github.com/llvm/llvm-project/commit/6ac3fd9706047304c52a678884122a3a6bc55432.diff

LOG: [clangd] Fix race in Global CDB shutdown

I believe the atomic write can be reordered after the notify, and that
seems to be happening on mac m1: http://45.33.8.238/macm1/2654/step_8.txt
In practice maybe seq_cst is enough? But no reason not to lock here.

https://bugs.llvm.org/show_bug.cgi?id=48998

Added: 
    

Modified: 
    clang-tools-extra/clangd/GlobalCompilationDatabase.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
index afe38993ef28..a38c8a57d161 100644
--- a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
+++ b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
@@ -34,6 +34,7 @@
 #include <atomic>
 #include <chrono>
 #include <condition_variable>
+#include <mutex>
 #include <string>
 #include <tuple>
 #include <vector>
@@ -553,7 +554,10 @@ class DirectoryBasedGlobalCompilationDatabase::BroadcastThread {
   }
 
   ~BroadcastThread() {
-    ShouldStop.store(true, std::memory_order_release);
+    {
+      std::lock_guard<std::mutex> Lock(Mu);
+      ShouldStop.store(true, std::memory_order_release);
+    }
     CV.notify_all();
     Thread.join();
   }


        


More information about the cfe-commits mailing list