diff --git a/emper/UnboundedBlockingMpscQueue.hpp b/emper/UnboundedBlockingMpscQueue.hpp index c28449abb61e2f500a9c666023d90b8c84ecb409..47dd19f6abea0b5c67e1d641cebac7da12d3f963 100644 --- a/emper/UnboundedBlockingMpscQueue.hpp +++ b/emper/UnboundedBlockingMpscQueue.hpp @@ -11,7 +11,7 @@ class UnboundedBlockingMpscQueue : protected Logger<LogSubsystem::U_B_MPSC_Q> , protected Blockable { private: - std::atomic<Context*> blockedContext; + std::atomic<Context*> blockedContext = nullptr; bool tPopped; T t; @@ -27,6 +27,10 @@ private: } void tryToGetElement(std::function<void(void)> postRetrieve) { + // tPopped indicates that 't' is a popped and usable value. + // Therefore if we tryToGet a new 't' while 't' is available the current 't' + // would be overridden and dropped. + assert(!tPopped); std::lock_guard<std::mutex> lock(queueMutex); if (!mpscQueue.empty()) { t = mpscQueue.front();