Boost logo

Boost :

From: Tan, Tom (Shanghai) (TTan_at_[hidden])
Date: 2008-06-06 04:58:11

While trying to understand the difference between wait() and async_wait,
I modified the tutorial example a little to test 2 timers at the same
time like this:


int test_timer()


    boost::asio::io_service io;


    size_t delay1 = 5;

    size_t delay2 = 3;


    boost::asio::deadline_timer t1(io,

    boost::asio::deadline_timer t2(io,


    boost::timer t;


    std::cout << t.elapsed() << " sec elapsed!\n";



    std::cout << t.elapsed() << " sec elapsed!\n";


    return 0;



I got this output:

3.004 sec elapsed!

5.007 sec elapsed!

However, I was expecting t2 and t1 to execute sequentially and thus

3.004 sec elapsed!

8 sec elapsed!


What was wrong with my understanding about synchronous waiting here?


Boost list run by bdawes at, gregod at, cpdaniel at, john at