我发现在最新的闰秒插入之后(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 issue
void 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