From b5aa6d5eb5d9d71a55d51ee2eef5cde952cf3a51 Mon Sep 17 00:00:00 2001 From: Dan Liew Date: Mon, 19 Dec 2016 22:36:42 +0000 Subject: [PATCH] Fix issue with bd1f07f864a7f1790cec08a306ccc17507f7e5a8 pointed out by @nunolopes . If `pthread_cond_signal()` is called while `m_mutex` is held then the timing thread might be woken up twice due to waking up from `pthread_cond_timeout()` (due to being signaled) but then being forced to sleep again because the thread calling `~imp()` is still holding `m_mutex` (which the timing thread needs to acquire). --- src/util/scoped_timer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/util/scoped_timer.cpp b/src/util/scoped_timer.cpp index 3b87f880f..f6b0429d9 100644 --- a/src/util/scoped_timer.cpp +++ b/src/util/scoped_timer.cpp @@ -230,8 +230,9 @@ struct scoped_timer::imp { } pthread_mutex_lock(&m_mutex); m_signal_sent = true; - pthread_cond_signal(&m_cond); pthread_mutex_unlock(&m_mutex); + // Perform signal outside of lock to avoid waking timing thread twice. + pthread_cond_signal(&m_cond); pthread_join(m_thread_id, NULL); pthread_cond_destroy(&m_cond);