On 6/30/09, Denis Bilenko <denis.bile...@gmail.com> wrote:
> On Thu, Jun 25, 2009 at 12:39 PM, Adrian Chadd<adr...@creative.net.au> wrote:
>  > I didn't think this was documented. As such, why would you expect them
>  > to fire in-order? :)
>
>
> On Thu, Jun 25, 2009 at 12:53 PM, Clint Webb<webb.cl...@gmail.com> wrote:
>  > If you need things to happen in a particular order, you need to sequence
>  > your timeouts from each other.  In an event based system, you cannot
>  > guarantee the order that the events will be fired.
>
>
> Why not? There is nothing that prevents the scheduler to fire such
>  events in the order
>  they were added. In fact, that what libevent seems to do when I call
>  event_add() before
>  entering the loop.
>
>  However, if I do the same inside a callback, the order is exactly
>  reversed except for the first event.
>
>  This suggests that (although I haven't looked through the code, so I
>  might be wrong)
>  this is accidental and libevent can be fixed to behave like that, but
>  nobody needed such
>  feature so far. It could also be that this is by design or that it's
>  impossible to implement
>  without performance penalty, in which case it's not worth bothering.
>  Could someone familiar
>  with the code shed the light on this?
>
>  I am implementing libevent hub for eventlet [1] and it has come to
>  depend on such behavior,
>  so I had to work around the issue. I don't like the workaround though.
>
>  [1] http://bitbucket.org/denis/eventlet/

The timeouts are kept in min-heap structure, whose goal is to make easy
to find smallest timeout.  It does not store the event addition order
in a way that works 100% of the time, although it may happen to work 90%
of the time.  This is expected and correct behaviour.

To have a guarantee that order is followed 100% of the time means
replacing the structure with something more complex that can give such
guarantees.  IMHO it is pointless.

IOW, you need to fix your code.  Increasing the timeval sort of works
but is ugly and will cause more wakeups for event loop.  Better is to
write your own API on top of libevent that can queue sequence of callbacks
to single libevent timer.  Or simply get rid of the requirement.

-- 
marko
_______________________________________________
Libevent-users mailing list
Libevent-users@monkey.org
http://monkeymail.org/mailman/listinfo/libevent-users

Reply via email to