Boost logo

Boost Users :

Subject: Re: [Boost-users] [asio] Timer cancellation behavior
From: Igor R (boost.lists_at_[hidden])
Date: 2010-05-05 16:29:18


> Here's the relevant code:
>
>
> boost::asio::io_service mIOService;
> boost::asio::deadline_timer mTimer(mIOService,
> boost::posix_time::seconds(3))
>
> inline void TimerHandler(const boost::system::error_code& err)
> {
>    cout << err;
>    if (err && err != boost::asio::error::operation_aborted)
>    {
>        cout << endl << "Watchdog elapsed" << endl;
>    }
> }
>
> void Start() {
>  mTimer.async_wait(TimerHandler);
>  mIOService.run();
> }
>
> // Cancels and restarts the watchdog timer - prevents a timeout
> void Restart() {
>    mTimer.cancel();
>    mTimer.async_wait(TimerHandler);
>    mIOService.reset();
>    mIOService.run();
> }

The flow is not clear. Your io_service goes out of work and run()
exits, then you call Restart()? All this happens on the same thread?
If so, try to move reset() to the beginning of the function.


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