Boost:asio同步定时器

asio的同步定时器跟sleep差不多:

#include 
#include 
#include 
#include 
using namespace boost::asio;
using namespace std;

unsigned long getTimestamp()
{
    return std::chrono::system_clock::now().time_since_epoch().count()/std::chrono::system_clock::period::den;
}

int main()
{
    io_service ios;
    cout << getTimestamp() << " Timer enable" << endl;
    deadline_timer t(ios, boost::posix_time::seconds(2));
    t.wait();
    cout << getTimestamp() << " Timer on" << endl;
    return 0;
}

运行程序输出:

1685079800 Timer enable
1685079802 Timer on

你可能感兴趣的:(#,Boost,c++)