Boost logo

Boost Users :

Subject: [Boost-users] [asio]
From: georg_at_[hidden]
Date: 2015-03-31 08:55:14


Hi all,
currently i try to understand boost asio a little better. Right now, i
just had a very simple asio program and started 2 timers asyncronously.

i expected the timer t to complete after the timer i.

//-------<-----------------
Current output:
10 s.
1 s.
//-------<-----------------
Expected output:
1 s.
10 s.
//-------<-----------------

Shouldn't complete the async_wait with 1 sec complete prior the 10 sec
async_wait?

I am on Windows 7 x64/ MSVC 2013(VS12) / Boost 1.57.0.

Regards
Georg

//-------<-----------------
#include <boost/asio.hpp>
#include <boost/system/error_code.hpp>
#include <iostream>

void wait_handler(const boost::system::error_code &ec) {
        if (!ec) std::cout << "10 s." << std::endl;
}

void irq_handler(const boost::system::error_code &ec) {
        if (!ec) std::cout << "1 s." << std::endl;
}

int main() {
        boost::asio::io_service io_service;
        boost::asio::deadline_timer t(io_service, boost::posix_time::seconds(10));
        boost::asio::deadline_timer i(io_service, boost::posix_time::seconds(1));

        t.async_wait(&wait_handler);
        t.async_wait(&irq_handler);

        io_service.run();
}
//-------<-----------------


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net