From f4d4c109d3b099534edb8b39dafd1f371b91ce4d Mon Sep 17 00:00:00 2001 From: John Fultz Date: Sat, 27 Jul 2019 00:16:14 -0500 Subject: Accommodate spurious wakeup of condition variables. Hopefully, this fixes crashes some users are seeing. --- sim.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sim.cpp b/sim.cpp index 5215906..912ceb5 100644 --- a/sim.cpp +++ b/sim.cpp @@ -619,7 +619,7 @@ void SimmedMoveMessageQueue::push(SimmedMoveMessage& msg) std::pair SimmedMoveMessageQueue::pop_or_terminate() { std::unique_lock lk(m_queueMutex); - if (m_queue.empty() && !m_terminateAll && m_terminateOne == std::thread::id()) + while (m_queue.empty() && !m_terminateAll && m_terminateOne != std::this_thread::get_id()) m_condition.wait(lk); std::pair result; result.second = m_terminateAll || m_terminateOne == std::this_thread::get_id(); @@ -636,7 +636,7 @@ std::pair SimmedMoveMessageQueue::pop_or_terminate() SimmedMoveMessage SimmedMoveMessageQueue::pop() { std::unique_lock lk(m_queueMutex); - if (m_queue.empty()) + while (m_queue.empty()) m_condition.wait(lk); SimmedMoveMessage result = std::move(m_queue.front()); m_queue.pop(); -- cgit v1.2.3