我发现在最新的闰秒插入(2016-12-31 23:59:60)之后,我们的 CentOS7 应用程序的工作线程在作业之间休眠 1 秒,开始立即唤醒休眠线程,而不是在一秒钟内。一般来说,所有睡眠都比预期的唤醒时间提前 1 秒醒来。
最简单有效的解决方案是重新启动盒子。但这在我们的案例中是不可取的。有没有办法在不重新启动的情况下解决这个问题?
附注。作为参考,这里有一个简单的 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 << " …Run Code Online (Sandbox Code Playgroud)