[library Boost.Asio [quickbook 1.4] [copyright 2003 - 2008 Christopher M. Kohlhoff] [license Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at [@http://www.boost.org/LICENSE_1_0.txt]) ] [category generic] ] [section Timer.5] In a multithreaded program ``''''''`` void print2() ``''''''`` { ``''''''`` if (count_ < 10) ``''''''`` { ``''''''`` std::cout << "Timer 2: " << count_ << "\n"; ``''''''`` ++count_; ``''''''`` timer2_.expires_at(timer2_.expires_at() + boost::posix_time::seconds(1)); ``''''''`` timer2_.async_wait(strand_.wrap(boost::bind(&printer::print2, this))); Just as it would with a call from a single thread ``''''''``int main() ``''''''``{ ``''''''`` boost::asio::io_service io; ``''''''`` printer p(io); ``''''''`` boost::thread t(boost::bind(&boost::asio::io_service::run, &io)); ``''''''`` io.run(); ``''''''`` t.join(); ``''''''`` return 0; ``''''''``} [endsect]