From 0fa88efc2b6340180148c3b3307ece1447a9fb7b Mon Sep 17 00:00:00 2001 From: John Regehr Date: Thu, 19 Nov 2020 14:42:55 -0700 Subject: [PATCH] scoped_timer: wait for timer thread before main thread continues (#4803) --- src/util/scoped_timer.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/util/scoped_timer.cpp b/src/util/scoped_timer.cpp index 44bf30f4c..33c6a2dc8 100644 --- a/src/util/scoped_timer.cpp +++ b/src/util/scoped_timer.cpp @@ -34,7 +34,7 @@ struct scoped_timer_state { std::timed_mutex m_mutex; event_handler * eh; unsigned ms; - int work; + std::atomic work; std::condition_variable_any cv; }; @@ -102,6 +102,8 @@ public: ~imp() { s->m_mutex.unlock(); + while (s->work == 1) + std::this_thread::yield(); } };