diff options
author | John Fultz <jfultz@wolfram.com> | 2019-07-27 00:16:14 -0500 |
---|---|---|
committer | John Fultz <jfultz@wolfram.com> | 2019-07-27 00:17:43 -0500 |
commit | f4d4c109d3b099534edb8b39dafd1f371b91ce4d (patch) | |
tree | 794688e05f8269ec010049b56447d85d9d03dc11 | |
parent | 74c2ba7d1ba19e3a7e900746f5ea0f58e42ceed0 (diff) |
Accommodate spurious wakeup of condition variables.
Hopefully, this fixes crashes some users are seeing.
-rw-r--r-- | sim.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -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(); |