diff --git a/Common/Thread/Event.h b/Common/Thread/Event.h index 3cc773da72..f675cd07d4 100644 --- a/Common/Thread/Event.h +++ b/Common/Thread/Event.h @@ -11,15 +11,21 @@ public: triggered_ = false; } + ~Event() { + // Make sure no one is still waiting, and any notify lock is released. + Notify(); + } + void Wait() override { - std::unique_lock lock; - if (!triggered_) { - cond_.wait(lock, [&] { return triggered_.load(); }); + if (triggered_) { + return; } + std::unique_lock lock(mutex_); + cond_.wait(lock, [&] { return triggered_.load(); }); } void Notify() { - std::unique_lock lock; + std::unique_lock lock(mutex_); triggered_ = true; cond_.notify_one(); }