Boost logo

Boost Users :

Subject: Re: [Boost-users] Asio timer - how to restart it?
From: Igor R (boost.lists_at_[hidden])
Date: 2008-10-23 11:42:52


> boost::asio::deadline_timer timer(io, boost::posix_time::seconds(5));
> boost::thread thread(boost::bind(&boost::asio::io_service::run, &io));
> timer.async_wait(on_time_out);
> delay(3);

Note that you set the timer timeout to be 5 second, but wait 3 second only.

> cout << second_clock::local_time() << " Restarting timer" << endl;
> timer.expires_from_now(boost::posix_time::seconds(5));

You just change the timeout here. To restart the timer you have to
call timer.async_wait().
By the way, note that the timer is not threadsafe so I'm not sure it's
legal to restart it here or to change its timeout this way.


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