Created
July 25, 2018 09:11
-
-
Save samsonchen1989/2f1485b8281b6dea1f42235375ea37fe to your computer and use it in GitHub Desktop.
Boost高精度定时器
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // AsioUdpClient.cpp: 定义控制台应用程序的入口点。 | |
| // | |
| #include "stdafx.h" | |
| #include <iostream> | |
| #include <boost/asio/high_resolution_timer.hpp> | |
| #include <boost/asio.hpp> | |
| std::chrono::milliseconds interval(1000); // 1000 mill second | |
| boost::asio::io_service io_service; | |
| boost::asio::high_resolution_timer timer(io_service); | |
| uint64_t index = 0; | |
| void tick(const boost::system::error_code& /*e*/) { | |
| ++index; | |
| std::cout << "tick:" << index << std::endl; | |
| // Reschedule the timer for 1 second in the future: | |
| timer.expires_from_now(interval); | |
| // Posts the timer event | |
| timer.async_wait(tick); | |
| } | |
| int main(void) { | |
| // Schedule the timer for the first time: | |
| timer.expires_from_now(interval); | |
| timer.async_wait(tick); | |
| // Enter IO loop. The timer will fire for the first time 1 second from now: | |
| io_service.run(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment