diff --git a/communication/driver.cpp b/communication/driver.cpp index c71d29b7..5fc7d390 100644 --- a/communication/driver.cpp +++ b/communication/driver.cpp @@ -9,7 +9,13 @@ using namespace icsneo; bool Driver::pushRx(const uint8_t* buf, size_t numReceived) { - bool ret = readBuffer.write(buf, numReceived); + bool ret; + { + // Write under the lock waitForRx checks its predicate with, or a notify between that check and + // the wait is lost and the reader sleeps the full timeout (1s for the read task) with data ready + std::lock_guard lk(rxWaitMutex); + ret = readBuffer.write(buf, numReceived); + } rxWaitCv.notify_all();