We've changed the time here in the UK this week. Since then, my Boost Timer has stopped working on my PC.
What should I do here if I want to run 10 second timer:
boost :: asio:: Io_service service; Promotion :: asio :: deadline_timer timer (service); Promotion: posix_time :: ptime time = boost :: posix_time :: microsec_clock :: local_time (); Timer.expires_at (time + boost :: posix_time :: time_duration (0, 0, 10)); Timer.async_wait (boost :: bind (& onTimeOut, boost :: asio :: placeholders :: error); Service.run (); Now that does not work, I was not waiting, but I hope it will take time in one hour and 10 seconds. To prove my point, if I do the following, it will end in 10 seconds:
boost :: asio :: io_service service; Promotion :: asio :: deadline_timer timer (service); Promotion: posix_time :: ptime time = boost :: posix_time :: microsec_clock :: local_time (); Timer.expires_at (time - boost :: posix_time :: time_duration (0, 59, 50)); Timer.async_wait (boost :: bind (& onTimeOut, boost :: asio :: placeholders :: error); Service.run (); Nobody is doing what I am doing wrong, or if I should do something to avoid this problem.
The problem you are experiencing is due to the default timer in Axiu, which boosts. The clock uses date_time, which is a wall clock timer. It represents real time because your wall clock is visible.
If you see the default time_traits asio deadline_timer ( boost / asio / time_traits.hpp ), its implementation of the code is now () uses boost :: posix_time :: microsec_clock :: universal_time () . This means that the Asoo understands what time it is, UTC is that when you pass a full time for expires_at () , then the ASIO will compare it with its understanding that it is time That is UTC, which is UTC. I believe that your local_time () is used only by coincidence because it is similar to the UTC. However, as already mentioned, using a clock that does not significantly improve daylight savings, the fundamental problem still exists.
UTC is still not a monotonic clock. This leap year will be leap and second, but primarily, the user (or more likely) can change the computer's clock, and your timers fail.
This is a very subtle problem that can be solved by defining its own asio :: time_traits specialization using a monotonic clock. For example clock_gettime (CLOCK_MONOTONIC) .
Comments
Post a Comment