From 0fbf4f02117fca1cf7f5ed84205d8504ce174f6f Mon Sep 17 00:00:00 2001 From: Sam McCall Date: Sat, 25 Jan 2020 15:22:12 +0100 Subject: [PATCH] [Support] Fix race in threading test, found by TSan --- unittests/Support/Threading.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/unittests/Support/Threading.cpp b/unittests/Support/Threading.cpp index 21baa55ef44..183c9aa7d71 100644 --- a/unittests/Support/Threading.cpp +++ b/unittests/Support/Threading.cpp @@ -32,8 +32,10 @@ public: { std::lock_guard 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() {