Starvation issue with Coro and AnyEvent

Marc Lehmann schmorp at schmorp.de
Fri Jan 24 00:22:45 CET 2014


On Thu, Jan 23, 2014 at 03:35:30PM -0500, Laurent <laurent.aml at gmail.com> wrote:
> The issue is that the "starved" coro never wakes up when the "greedy" one
> runs.

Right, you would need to give the event loop a higher priority (or your
busy thread a lower one, or explicitly poll for events) - the rules are
explained in the Coro::AnyEvent manpage.

> The coro scheduler is supposed to cede to a coro with same or higher
> priority, that is longest in the ready queue. So I would have expected that
> the greedy coro would cede to the evloop coro.

It does, but the event loop sees that there is outstanding work to do and
doesn't poll for new events. This is pretty much like event loops work
themselves: they do not usually poll for new events as long as there are
active/pending watchers, which in Coro, are represented by runnable threads.

It is also consistent with coro not switching threads unless it has to: in
this case, it doesn't poll for events until it has to. If you give coro
something to run, it will prefer running this over gathering new events.

And with priorities you can influence this to your liking: If you want to
poll on every cede and do background work, you should give your thread a
lower priority the the event loop - your process will then automatically
start polling on sleep, cede and so on.

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



More information about the anyevent mailing list