linux – 如何在不重启的情况下修复闰秒睡眠问题

linux – 如何在不重启的情况下修复闰秒睡眠问题,第1张

概述我发现在最新的闰秒插入后(2016-12-31 23:59:60),我们的CentOS7应用程序让工作线程在作业之间休眠1秒钟,开始立即唤醒睡眠线程而不是一秒钟. 通常,所有睡眠都在预期唤醒时间之前1秒唤醒. 最简单和有效的解决方案是重启盒子.但在我们的案例中,这是不可取的. 有没有办法解决这个问题而无需重启? PS.作为参考,这是C中用于再现问题的简单程序. #include <boost/da 我发现在最新的闰秒插入后(2016-12-31 23:59:60),我们的CentOS7应用程序让工作线程在作业之间休眠1秒钟,开始立即唤醒睡眠线程而不是一秒钟.
通常,所有睡眠都在预期唤醒时间之前1秒唤醒.

最简单和有效的解决方案是重启盒子.但在我们的案例中,这是不可取的.
有没有办法解决这个问题而无需重启?

PS.作为参考,这是C中用于再现问题的简单程序.

#include <boost/date_time.hpp>#include <boost/thread.hpp>#include <iostream>using namespace std;// this has to be run in a thread to be able to detect the issuevoID check_thread(){    size_t expected_delay = 1000;    cout << "Expected delay: " << expected_delay << " ms" << endl;    boost::posix_time::ptime t1 = boost::posix_time::microsec_clock::universal_time();    boost::this_thread::sleep(boost::posix_time::milliseconds(1000));    boost::posix_time::ptime t2 = boost::posix_time::microsec_clock::universal_time();    size_t actual_delay = (t2 - t1).total_milliseconds();    cout << "Actual delay: " << actual_delay << " ms" << endl;    if (abs(expected_delay - actual_delay) > 900) {        cout << "Too big delay difference: " << (expected_delay - actual_delay) << endl;        cout << "Possible leap second issue" << endl;    }    else {        cout << "No issues found" << endl;    }}int main(){    boost::thread_group g;    g.create_thread(check_thread);    g.join_all();    return 0;}

建造:

g++ sleep_test.cpp -Wl,-Bstatic -lboost_thread -lboost_system -lboost_date_time -Wl,-Bdynamic -rdynamic -pthread
解决方法 您的系统时间是否与ntpd或ptp同步?如果没有,请更新您的tzdata包.

For systems not synchronized by ntpd or ptp an updated tzdata package
that contains the December 31st leap second is required. The updated
tzdata package was released as part of RHEA-2016-1982,and any systems
using RHEL 7 that are not synchronized by ntpd or ptp should update to
tzdata-2016g-2.el7,or a later version,to receive this fix.

Resolve Leap Second Issues in Red Hat Enterprise Linux

总结

以上是内存溢出为你收集整理的linux – 如何在不重启的情况下修复闰秒睡眠问题全部内容,希望文章能够帮你解决linux – 如何在不重启的情况下修复闰秒睡眠问题所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/1037020.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-24
下一篇2022-05-24

发表评论

登录后才能评论

评论列表(0条)

    保存