Author: Sam McCall Date: 2020-01-25T15:31:55+01:00 New Revision: d08563486e06df3ddb4d7c1018d1e1e762690ee8
URL: https://github.com/llvm/llvm-project/commit/d08563486e06df3ddb4d7c1018d1e1e762690ee8 DIFF: https://github.com/llvm/llvm-project/commit/d08563486e06df3ddb4d7c1018d1e1e762690ee8.diff LOG: [clangd] Make Notification a little safer. I just fixed a test involving a similar Notification class: 18e6a65bae93a The pattern (notify() on one thread, wait() and then destroy the Notification on the other) seems innocuous enough. I'm not sure we actually use it in clangd, but better safe than sorry. Added: Modified: clang-tools-extra/clangd/Threading.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clangd/Threading.cpp b/clang-tools-extra/clangd/Threading.cpp index 016a90297c32..47c91f449d3f 100644 --- a/clang-tools-extra/clangd/Threading.cpp +++ b/clang-tools-extra/clangd/Threading.cpp @@ -20,8 +20,10 @@ void Notification::notify() { { std::lock_guard<std::mutex> Lock(Mu); Notified = true; + // Broadcast with the lock held. This ensures that it's safe to destroy + // a Notification after wait() returns, even from another thread. + CV.notify_all(); } - CV.notify_all(); } void Notification::wait() const { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits