Hi,

I faced some strange behavior while using timers (boost_1_38_0/boost_1_39_0).
Here is an easy way to reproduce such behavior (note: I use async timeouts and a single thread):

=experiment 1=
Timer1 expires after 2 seconds and reschedules itself to fire again 2 seconds later.
Timer2 expires after 2 seconds and cancels Timer1.

Result:
  Timer2's handler gets called but the cancel call on Timer1 returns 0.
  Timer1's handler gets called (although it should have been cancelled) and therefore, Timer1 repeats itself indefinitely.

=experiment 2=
Timer1 expires after 1995 milliseconds and primes itself to fire again 1995 milliseconds later.
Timer2 expires after 2 seconds and cancels Timer1.

Result:
  Timer1's handler gets called and reschedules itself.
  Timer2's handler gets called and Timer1 gets canceled properly.

=experiment 3=
Timer1 expires after 2005 milliseconds and primes itself to fire again 2005 milliseconds later.
Timer2 expires after 2 seconds and cancels Timer1.

Result:
  Timer2's handler gets called and Timer1 gets canceled properly.

=experiment 4=
Repeat experiment 1 but change the expiration time of Timer1 instead of canceling it from Timer2's handler.

Result:
  Timer2's handler gets called and Timer1 gets rescheduled properly. Note that Timer1's handler doesn't get called at all before the new expiry time although it should be called with an operation_aborted error code.

=summary=
When Timer1 and Timer2 expire at a very close time, Timer2 cannot cancel Timer1 although it can reschedule it.
Is it an expected behavior?
Is it due to the design of Asio?


Regards,

Laurent