diff --git a/src/libYARP_os/src/yarp/os/NetworkClock.cpp b/src/libYARP_os/src/yarp/os/NetworkClock.cpp index ae5754626b..be09b27de5 100644 --- a/src/libYARP_os/src/yarp/os/NetworkClock.cpp +++ b/src/libYARP_os/src/yarp/os/NetworkClock.cpp @@ -103,7 +103,6 @@ bool NetworkClock::Private::read(ConnectionReader& reader) } timeMutex.lock(); - bool previousTimestampAvailable = initted; double oldTime = _time; sec = bot.get(0).asInt32(); nsec = bot.get(1).asInt32(); @@ -111,13 +110,14 @@ bool NetworkClock::Private::read(ConnectionReader& reader) initted = true; timeMutex.unlock(); - // If the clock time has been reset (i.e. it jumped back in time) - // release all the threads currently waiting - bool clockResetDetected = previousTimestampAvailable && (_time < oldTime); listMutex.lock(); auto waiter_it = waiters->begin(); - while (waiter_it != waiters->end()) { - if (waiter_it->first - _time < 1E-12 || clockResetDetected) { + // Update the wake-up time. In case of a time reset it closes the gap between the waiter and _time. + waiter_it->first = _time + (waiter_it->first - oldTime); + + while (waiter_it != waiters->end()) + { + if (waiter_it->first - _time < 1E-12) { Semaphore* waiterSemaphore = waiter_it->second; waiter_it = waiters->erase(waiter_it); if (waiterSemaphore != nullptr) {