Stopping a watcher in one callback where another may be called

Brandon Black blblack at
Wed Mar 30 06:52:10 CEST 2011

On Tue, Mar 29, 2011 at 11:30 PM, Arlen Cuss <celtic at> wrote:
> My question now: say both the ev_timer and ev_io get triggered at the
> same time. If the ev_timer callback gets called first, then the ev_io is
> stopped and deallocated (as is all the auxiliary data that the ev_io
> callback will be using, as it happens).

If the timer callback happens to run first, and does ev_io_stop on the
related io watcher, libev won't try to run the io callback (even if it
had pending events for the same eventloop iteration).  You can set the
order of execution for related events in a single eventloop iteration
by setting watcher priorities (e.g. for standard network stuff, you
might set the io watcher as higher priority than the idle timeout
watcher, so that if they trigger on the same loop iteration the
connection isn't unnecessarily killed.  Or if proxying buffered
network traffic, you might set write callbacks higher than read to
minimize peak buffer allocation).

More information about the libev mailing list