c++ - boost asio timer : run 2 timers -
i try run asynchronous timer , synchronous timer : here code : boost::asio::io_service io; boost::asio::steady_timer t1(io); boost::asio::steady_timer t2(io); void callback(boost::system::error_code const&) { std::cout << "foo" << std::endl; t1.expires_from_now(boost::chrono::seconds(1)); t1.async_wait(&callback); } int main(int argc, char **argv) { t1.expires_from_now(boost::chrono::seconds(1)); t1.async_wait(&callback); io.run(); t2.expires_from_now(boost::chrono::seconds(5)); t2.wait(); io.run(); std::cout << "finish" << std::endl; return exit_success; } i foo printed 5 times, , finish printed. in code, foo printed every 1 second , finish never reached. how achieve want ? thanks according the documentation of io_service::run : the run() function blocks until work has finished , there no more handlers dispatched, or until io_service has been s...