Critical sections with ev++.h

Marc Lehmann schmorp at
Sun Jul 19 10:12:32 CEST 2020

On Fri, Jul 17, 2020 at 05:10:32PM +0200, Michele Santullo <m.santullo at> wrote:
> notifications in separate threads and just print something to stdout when they 
> occur. It's mostly working but I get occasionas crashes, which makes me think 
> it might be a concurrency issue.

Right, it also means you are not protecting calls to the same loop with a
mutex, which would get rid of the crashes.

> incredis/src/branch/master/src/async_connection.cpp#L122 that I was calling 
> ev_set_loop_release_cb(). If memory serves me right that was needed precisely 

ev_set_loop_release_cb won't get rid of the crashes for you, the purpose
of that call is so that you can release your mutex for longer times, i.e.
if another thread wants to acquire the mutex while libev is waiting in the
kernel it normally can't, because ev_run/ev_loop calls need to be also
protected via that mutex, and without ev_set_loop_release_cb this mutex
will be held while libev is polling the kernel.

> to solve some weird crash that I was getting, but in the C++ API I can't find 
> anything similar. Is it done is some other way in C++?

ev_set_loop_release_cb works fine in C++.

Note that, while ev++.h has some classes representing the main loop, only
the watcher classes are a) documented b) maintained and c) guaranteed to
some degree to stay. Everything else is undocumented, might be broken and
might go away or change incompatibly at any time.

> Also, small side question, is there an IRC channel for questions and 
> discussions about libev?

You can go to #schmorpforge - I'll be there as user
schmorp, and some other users might also be able to help with libev. You
might have to /msg me to get my attention, though.

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

More information about the libev mailing list