summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Fultz <jfultz@wolfram.com>2019-07-27 00:16:14 -0500
committerJohn Fultz <jfultz@wolfram.com>2019-07-27 00:17:43 -0500
commitf4d4c109d3b099534edb8b39dafd1f371b91ce4d (patch)
tree794688e05f8269ec010049b56447d85d9d03dc11
parent74c2ba7d1ba19e3a7e900746f5ea0f58e42ceed0 (diff)
Accommodate spurious wakeup of condition variables.
Hopefully, this fixes crashes some users are seeing.
-rw-r--r--sim.cpp4
1 files 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<SimmedMoveMessage, bool> SimmedMoveMessageQueue::pop_or_terminate()
{
std::unique_lock<std::mutex> 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<SimmedMoveMessage, bool> result;
result.second = m_terminateAll || m_terminateOne == std::this_thread::get_id();
@@ -636,7 +636,7 @@ std::pair<SimmedMoveMessage, bool> SimmedMoveMessageQueue::pop_or_terminate()
SimmedMoveMessage SimmedMoveMessageQueue::pop()
{
std::unique_lock<std::mutex> 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();