2017-01-03 07:47:38 UTC
I am doing a program that use asio to construct a timer thread. The thread use asio to async_wait many timers. These timers are constructed by boost::asio::system_timer. These timers are mostly designed to fire only once. When they are fired or canceled, I put them to a free queue to reuse.
But when I reuse these times, I called expire_from_now() and async_wait() again on the timer, I got the timer fired immediately with error_code set to "ec == boost::asio::error::operation_aborted". And the timer are not fired after like 5 seconds late as I set to expire_from_now(seconds(5)).
How to reuse the timer correctly?
My codes basically are as follows:
m_timer.cancel(); // I tried to cancel the timer first, but no use, I still get the timer fired at once
m_timer.async_wait(boost::bind(&qmInnerTimer::Fire, this, _1));