#include <boost/asio.hpp> #include <iostream> void handle1(const boost::system::error_code& ec) { std::cout << "5.s" << std::endl; } void handle2(const boost::system::error_code& ec) { std::cout << "10.s" << std::endl; } int main() { boost::asio::io_service io_service;//io服务 boost::asio::deadline_timer timer1(io_service, boost::posix_time::seconds(5));//定时器timer1 timer1.async_wait(handle1);//异步等待 boost::asio::deadline_timer timer2(io_service, boost::posix_time::seconds(10));//定时器timer2 timer2.async_wait(handle2);//异步等待 io_service.run();//阻塞调用,这个是必须的,这样才能将控制权交给操作系统,可以再一个线程里面阻塞,这个和libevent派发线程很像 }
时间: 2024-10-13 03:03:12