提高:: deadline_timer可能会失败时,系统时钟被修改 [英] boost::deadline_timer can fail when system clock is modified

查看:1287
本文介绍了提高:: deadline_timer可能会失败时,系统时钟被修改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于可以在阅读:

<一个href=\"https://svn.boost.org/trac/boost/ticket/3504\">https://svn.boost.org/trac/boost/ticket/3504

这是周期性的超时和使用deadline_timer :: expires_at()(类似的Boost定时器教程,3TH例如)可能会失败(例如,使用date命令,如果你的操作系统是Linux系统)。

a deadline_timer that timeouts periodically and which is implemented using deadline_timer::expires_at() (like the example in Boost Timer Tutorial, 3th example) will probably fail if the system time is modified (for example, using the date command, if your operating system is Linux).

现在是否有执行此操作,使用Boost的简单和appropiate的方式?我不想用deadline_timer :: expires_from_now(),因为我可以确认它比手动更新过期时间不准确。

Is there a simple and appropiate way of performing this operation now, using Boost? I do not want to use deadline_timer::expires_from_now() because I could verify that it is less accurate than "manually" updating the expiry time.

作为一个时间的解决方案,我决定,创下新的expires_at值之前,现在计算之间的时间段()和expires_at()。如果是的两倍多周期延时的话,我分外使用expires_from_now()用新的绝对时间重新同步。

As a temporal solution I decide to, before setting a new expires_at value, calculate the time period between now() and expires_at(). If it is more than double the periodic delay, then I exceptionally use expires_from_now() to resync with the new absolute time.

推荐答案

在升压1.49+,的 Boost.Asio的提供<一个href=\"http://www.boost.org/doc/libs/1_53_0/doc/html/boost_asio/reference/steady_timer.html\"><$c$c>steady_timer.这个计时器使用<一个href=\"http://www.boost.org/doc/libs/1_53_0/doc/html/chrono/users_guide.html#chrono.users_guide.tutorial.clocks\"><$c$c>chrono::steady_clock,未受到修改系统时钟单调时钟

In Boost 1.49+, Boost.Asio provides steady_timer. This timer uses chrono::steady_clock, a monotonic clocks that is not affected by changes to the system clock.

如果您不能使用升压1.49+,然后选中更改计时器或时钟是一个合理的替代解决方案。虽然这是一个实现细节,Boost.Asio的可能限制的时间花费在等待在其反应器的事件的数量,因此,它可以定期检测更改系统的时间。例如,反应器使用实施的epoll 将等待最多5分钟。因此,在不迫使在反应器的中断(例如,设置一个计时器新的到期时间),则可以采取Boost.Asio的最多5分钟检测更改系统时间之前

If you cannot use Boost 1.49+, then checking the timers or clocks for changes is a reasonable alternative solution. While it is an implementation detail, Boost.Asio may limit the amount of time spent waiting on an event in its reactor, so that it can periodically detect changes to system time. For example, the reactor implementation using epoll will wait a maximum of 5 minutes. Thus, without forcing an interrupt on the reactor (such as setting a new expiration time on a timer), it can take Boost.Asio up to 5 minutes before detecting changes to system time.

这篇关于提高:: deadline_timer可能会失败时,系统时钟被修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆