]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/asio/example/cpp03/tutorial/timer5/timer.cpp
5 // Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
12 #include <boost/asio.hpp>
13 #include <boost/thread/thread.hpp>
14 #include <boost/bind.hpp>
15 #include <boost/date_time/posix_time/posix_time.hpp>
20 printer(boost::asio::io_service
& io
)
22 timer1_(io
, boost::posix_time::seconds(1)),
23 timer2_(io
, boost::posix_time::seconds(1)),
26 timer1_
.async_wait(strand_
.wrap(boost::bind(&printer::print1
, this)));
27 timer2_
.async_wait(strand_
.wrap(boost::bind(&printer::print2
, this)));
32 std::cout
<< "Final count is " << count_
<< std::endl
;
39 std::cout
<< "Timer 1: " << count_
<< std::endl
;
42 timer1_
.expires_at(timer1_
.expires_at() + boost::posix_time::seconds(1));
43 timer1_
.async_wait(strand_
.wrap(boost::bind(&printer::print1
, this)));
51 std::cout
<< "Timer 2: " << count_
<< std::endl
;
54 timer2_
.expires_at(timer2_
.expires_at() + boost::posix_time::seconds(1));
55 timer2_
.async_wait(strand_
.wrap(boost::bind(&printer::print2
, this)));
60 boost::asio::io_service::strand strand_
;
61 boost::asio::deadline_timer timer1_
;
62 boost::asio::deadline_timer timer2_
;
68 boost::asio::io_service io
;
70 boost::thread
t(boost::bind(&boost::asio::io_service::run
, &io
));