[Ace-users] New timer event during handle_timeout processing

Eric.Malenfant at gmail.com Eric.Malenfant at gmail.com
Thu Mar 13 12:36:01 CDT 2008


On Mar 13, 12:11 pm, Arlekin <vadim.shme... at ovsoft.ru> wrote:
> Good day.
> I very interesting whats happens if new timer event arrives during
> handle_timeout processing. As i can suppose there are some cases:
> 1) Reactor has 1 thread. Will be new event discarded or queued for
> later processing?

Queued. More precisely, timer events don't "arrive" by themselves. A
timeout is just a timestamp + a reference to an event handler, in a
timer queue. On each turn, the event handling loop of the Reactor
checks the timestamp of the element at the head of this queue and, if
this timestamp is larger than the current time, it calls
handle_timeout on the associated handler.

> 2) Reactor has 2 (or more) threads. Another free reactor's thread will
> be process it event. But whats happens if during that processing,
> first thread returns -1 from handle timeout?

I assume that you refer here to two threads processing the same
recurring timer (otherwise, returning -1 from handle_timeout on one
would not affect the other, and a non-recurring timer can not be
dispatched more than once). In that case, things can become tricky:
For example, returning -1 from handle_timeout will normally cause the
Reactor to call handle_close on the event handler. If, in
handle_close, the event handler calls "delete this", the other thread
ends up running handle_timeout on a deleted handler.

Depending on which ACE version you are using, I think, IIRC, that you
can enable reference-counting on your event handlers to avoid that
"destruction race".

HTH,

Éric Malenfant



More information about the Ace-users mailing list