Boost logo

Boost Users :

Subject: [Boost-users] ASIO io_service behaviour
From: Philip Gaskell (philip.gaskell_at_[hidden])
Date: 2008-10-30 11:40:04


Hi all,

I have got some code to test the behavior of io_service. The relevant code is as
follows:

void ioservice_lifotest()
{
        boost::asio::io_service io;
        boost::asio::deadline_timer t(io, boost::posix_time::seconds(6));

        boost::asio::io_service io2;
        boost::asio::deadline_timer t1(io2, boost::posix_time::seconds(1));
        boost::asio::deadline_timer t2(io2, boost::posix_time::seconds(2));
        boost::asio::deadline_timer t3(io2, boost::posix_time::seconds(3));
        boost::asio::deadline_timer t4(io2, boost::posix_time::seconds(4));

        t.async_wait(printHello);
        t1.async_wait(print1);
        t2.async_wait(print2);
        t3.async_wait(print3);
        t4.async_wait(print4);

        io.run();
        std::cout << "bleh\n";
        io2.run();

        std::cout << "done\n";
}

printHello(), print1(), print2(), print3() and print4() are simple functions
that print different messages to the console.

I was expecting printHello to be called first, then print1, then print2, then
print3 and print4, because that is the order the events were added to the
io_service service. However these functions were called in reverse order. It is
as though the underlying queue mechanism is actually a stack.

I expect I have missed some of, or misunderstood the documentation, but a few
hints as to what is happening will be appreciated.

-- 
Regards,
Phil
E: philip.gaskell_at_[hidden] |  M: +44(0)7891 199 959 |  W: www.momote.com
EMAIL DISCLAIMER
The contents of this electronic mail message and any attachments (collectively " 
this message") are confidential, possibly privileged and intended only for its 
addressee ("the addressee"). If received in error, please delete immediately 
without disclosing its contents to anyone. Neither the sender nor its management 
or employees will in any way be responsible for any advice, opinion, conclusion 
or other information contained in this message or arising from its disclosure.
Registered office: 8 The Parks, Haydock, Newton-Le-Willows, Merseyside. WA12 0JQ
Registered in England No. 4410772.

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