Does an event loop support multiple threads?

Marc Lehmann schmorp at
Wed May 23 06:48:15 CEST 2012

On Tue, May 22, 2012 at 02:32:08PM -0400, "Hassink, Brian" <Brian.Hassink at> wrote:
> I just asked a similar question on the libevent mailing list and was told that it currently does not.  I understand libev is modeled on libevent, but thought I'd ask here as well...

both libevent and libev support multiple threads, in slightly different

> The project I'm working on involves up to 2000 "active" connections.  My
> initial thought was that the associated read and write events would be
> pending in the same event_base / ev_loop instance, and that a thread
> pool would be used to handle them concurrently.  Would I have each
> thread in the pool invoke event_base_dispatch() / ev_run() with the same
> event_base / ev_loop instance?

I can only imagine that that would be quite inefficient, which is why it's
not typically implemented that way.

The typical way to implement this is to have one (or more) event loops
per thread with one thread or so per core, or have one event loop that is
passd in round-robin among multiple threads (or some variation thereof).

Sometimes you also have a thread pool for other purposes, but thread pools
at least double the communications overhead over the alternatives, so are
usually only reasonable for long-running operations, or when you have to do
something that will block.

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

More information about the libev mailing list