Questions - partly newbie

Marc Lehmann schmorp at
Mon Jun 29 13:56:16 CEST 2015

On Mon, Jun 29, 2015 at 01:09:30PM +0200, " Software GmbH - Martin Peter Hanke" <mphanke at> wrote:
> The current architecture spawns a thread for the server, accepting
> connections in an own ev::default_loop.

As a (likely unrelated) sidenote, ev::default_loop is undocumented
functionality - you can use it of course, but it can break or fail any
time.  Only the c++ watchers classes are currently documented.

> 1. When running an event loop with multiple watchers, per iteration only one
> watcher is called - is this intended or is my implementation wrong?

Either you are measuring this wrong, or it's actually correct behaviour
(the event loop will run all watchers, but if there is only one ready,
only one will run), or you somehow corrupt memory (see below).

> 2. Having the ev::timer running, at some point the ev::io watchers stop
> working. are the watcher excluding each other?

Unless you stop them properly, the most likely cause is memory corruption
somewhere, which is very common when threads are involved, as many people
forget locking when using threads, when using libev.

In general, with threads, you have to protect all accesses to shared data
structures. That includes a loop and its associated watchers - so if you
modify watchers in use by another thread, the behavior you see would be one
of several typical symptoms.

As is corrupting watcherrs the "conventional" way, such as freeing the
watcher while it is active, or overwriting it.

> 3. Sometimes the latency is extremly high, when accepting connections. I
> can't really find a reason for this. Any hints?

A typical case (when threads are involved :) would be that you add a
watcher to a loop running in another thread, without locking. At best, the
other loop would pick it up one or two iterations later, at worst, you get
silent data corruption or start WW 3.

> 4. Is there any known difference between ev++ and ev I should be caring
> about?

ev++.h is just thing wrappers that call libev functions, it's not
different than you writing your own wrappers for example.

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

More information about the libev mailing list