timertt: std::condition_variable::wait_until

9 views
Skip to first unread message

sazo...@gmail.com

unread,
Feb 5, 2022, 1:22:56 AM2/5/22
to SObjectizer
Hello, my project have the next poblem.

SO5 version: 5.6
OS: Ubuntu 20.04.3 LTS
compiler: gcc  - 8.3

Change of system time corrupts timers. It's supposed current time is X, I set system time as X - 1 hour. Event timers will be triggered in this case after 1 hour + period.
I think it'can be caused by use std::condition_variable::wait_until in timertt library.
ltrace util shows that clock_gettime uses CLOCK_REALTIME for this method.


Is it normal ? What's about  usage of std::condition_variable::wait_for ?

Best regards, Dmitry
 

Yauheni Akhotnikau

unread,
Feb 5, 2022, 1:48:55 AM2/5/22
to SObjectizer
Hi!

SObjectizer's timers are based on timertt's timer, and timertt doesn't support wall-clock timers, only relative ones. It means that timertt doesn't support timers that should be fired at, for example, 15:05:45. Only timers that have to be fired after, for example, 15 seconds from now.

For that purpose, timertt uses monotonic clock (std::chrono::steady_clock) and that monotonic clock shouldn't be affected by time adjustment (if stdlib is implemented correctly). I have checked that behavior during the development of timertt and it worked at that time.

I don't believe that wait_for for steady_clock will work differently. Maybe it even implemented just as wait_until(now()+pause).

I'll check the behavior you described, but only at the beginning of the next week.

sazo...@gmail.com

unread,
Feb 5, 2022, 9:12:16 AM2/5/22
to SObjectizer
yes, i'm not right, there is no changes with wait_for.

Just from cppref:


"The standard recommends that the clock tied to timeout_time be used to measure time; that clock is not required to be a monotonic clock. There are no guarantees regarding the behavior of this function if the clock is adjusted discontinuously, but the existing implementations convert timeout_time from Clock to std::chrono::system_clock and delegate to POSIX pthread_cond_timedwait so that the wait honors adjustments to the system clock, but not to the user-provided Clock."

суббота, 5 февраля 2022 г. в 09:48:55 UTC+3, eao...@gmail.com:

Yauheni Akhotnikau

unread,
Feb 7, 2022, 5:02:17 AM2/7/22
to SObjectizer
I've done a couple of checks under Kubuntu 20.04 and GCC 9 and 10.

There is a problem described with GCC 9. And changing from `wait_util` to `wait_for` only helps for one case (when the time is adjusted backward), but still doesn't work for other cases (when the time is adjusted forward, at least in my tests).

There aren't problems at all with GCC 10 (with the original use of `wait_util`).

It seems that GCC 10 is shipped with a more correct implementation of the standard C++ library.
Reply all
Reply to author
Forward
0 new messages