Feature request: ability to use libeio with multiple event loops

Marc Lehmann schmorp at schmorp.de
Tue Dec 20 16:17:09 CET 2011

On Tue, Dec 20, 2011 at 02:34:52PM +0100, Hongli Lai <hongli at phusion.nl> wrote:
> I'm writing a multithreaded evented server in which I have N threads
> (N=number of CPU cores) and one libev event loop per thread. I want to
> use libeio but it looks like libeio depends on global variables so
> this isn't going to work.

global variables are entirely fine with threads (libeio itself uses

> I'd like to request the ability to use libeio with multiple event
> loops. This probably involves changing the API so that each libeio
> function accepts a context object.

You can already do that - lock around request submit calls and have a
receiving thread that calls eio_poll and does whatever it needs to do to
notify other threads.

You could e.g. pthread_cond_signal in the want callback and wait for that
in the receiving thread (thats tricky of course, a pipe is much simpler

See http://lists.schmorp.de/pipermail/libev/2011q4/001585.html for soem

                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 libev mailing list