Question about ev_async and shared state

Marc Lehmann schmorp at
Wed Feb 25 15:08:14 CET 2009

On Wed, Feb 25, 2009 at 12:23:35PM -0000, Rick Taylor <rick at> wrote:
> Hi, I might be misreading the trunk source code, but is it true that the asynchronous event handling uses a single global variable for handling asynch events (gotasync in ev.c)?

no, gotasync is simply a global variable to signal an async event - there is
one variable per event in the async watchers.

btw, could you follow your mail messages better in the future? all your
paragraphs are a single long line, which makes it very hard to read it.

> having implemented that, why use a global variable to indicate the
> condition.

it's simple and fast.

> Why not pass a more complex message via the pipe (rather than the single
> int) keeping the notification private to the individual event_loop.

each event loop has it's own pipe and signal variable already and each
async has it's own variable, there is no need for a more complex message
(there is one "int" per async watcher, the best you can do without getting
into atomicity issues).

apart from having no need, the problem is: how do you queue "more complex
messages" (when the pipe is full)? I know of no way to queue anything
in an async-safe way, and so far, nobody has come up with such a method
that is reasonably portable (doesn't require threads for example or

libev avoids the pipe-full issue by using gotasync to only signal the
condition once, which also saves on syscalls.

> I hope I'm not wasting anyone's time and that I haven't missed the point here.

Not sure if you missed the point :) But if your primary concern is
per-loop-asyncs, then this is already implemented.

                The choice of a       Deliantra, the free code+content MORPG
      -----==-     _GNU_    
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      pcg at
      -=====/_/_//_/\_,_/ /_/\_\

More information about the libev mailing list