diff --git a/clang-tools-extra/clangd/Threading.cpp b/clang-tools-extra/clangd/Threading.cpp index 016a90297c3283..47c91f449d3f5e 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 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 {