On Fri, Jun 03, 2011 at 07:12:25AM +0200, Denis Bilenko
<[email protected]> wrote:
> > 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.
> >
>
> Well, in gevent, people sometimes use sleep(0) as a way to yield to other
> current coroutines.
I hope that gevent documents this as working that way then, and makes sure it
actually does. What a horrible hack though :(
Of course, this is just a shortcoming in gevent (not having some kind of
yield), or a shortcoming in the users (abusing a sleep when all they want
is a yield, or a poll).
In general, there are many possible ways of "yielding" in coroutine
systems, one that polls for events, one that polls for events and maybe
sleeps for a while, one that yields, but does not poll for events and so
on.
A good system has functions that are documented to actually achieve this
(for example Coro has cede/poll/sleep/idle/idle_upto, to allow users to
specify what they really want or need).
In addition, or separately, in a system that has priorities, the event
loop could have a priority as well - are you then sure that sleep(0) of a
high priority taks should run a lower-priority event loop?
> However, I can also handle 0 separately in sleep(), make it use ev_idle or
> ev_check in that case.
Actually, I would humbly suggest fixing the API instead :) sleep(0) could
mean just about anything (from instantly returning, to yielding, to
polling etc.), and specialcasing this as "non blocking poll" is just one
of many possibilities, most of which have little to do with the concept of
sleeping for a time.
--
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