On Thu, Jun 02, 2011 at 09:51:13PM +0200, Denis Bilenko 
<[email protected]> wrote:
> > +  backend_fudge  = 1e-3;
> >
> 
> This helps with CPU load but it still causes ev_timer(0) to issue
> ev_sleep(>0) which puts the process to sleep.

As it should, see below.

> However, for ev_timer with AT = 0, the guarantee that the timers are only
> executed after AT seconds is passed is satisfied immediately,

No, "right now" is not also "past now". The reason why "past" is so
important, imagine your clock had only a 1 seocnd resolution.

Imagine at one point it is second 1000, and then you start a 1 second
timeout. When the clock then turns to 1001 any amount of time from 0 to 1
second might have been passed, breaking the "at least" guarantee of libev.

In other words, the only way to implement "at least" behaviour is to fire
"past this time" not "past or at this time", because it is, in general,
impossible to have a notion of "this time" that isn't already outdated.

As for 0, we indeed don't need to care, but introducing this special case
would make the timeout values nonproportional to the actual time. And that
in turn would destroy the property that adding something to a timeout
value will make the timer fire this much earlier or later (within the
limits of libev's control).

I think having time run strictly monotonously is more important than the
special case of a 0-second timer - a 0 second timer is definitely NOT a
special case for the user of libev.

> It is possible to use ev_timer(-1) but that's not as clear as ev_timer(0).

Why would anybody want to use specifically a 0-second timer (where the 0
isn't just the chance result of some calculation)?

The only reason I can know from past experience is that some people try
to abuse 0-second timers as some replacement for idle watchers, possibly
because that hack was the only way to get some kind of idle behaviour with
some other event loop.

The fix for that is an idle watcher, it has defined semantics for this
case.

-- 
                The choice of a       Deliantra, the free code+content MORPG
      -----==-     _GNU_              http://www.deliantra.net
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      [email protected]
      -=====/_/_//_/\_,_/ /_/\_\

_______________________________________________
libev mailing list
[email protected]
http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev

Reply via email to