Adding watchers on the fly to event loops

Marc Lehmann schmorp at
Wed Jul 10 13:06:58 CEST 2013

On Wed, Jul 10, 2013 at 03:57:40PM +0530, Aravindh Ramaswamy <aravindhramu at> wrote:
> I have started an empty event loop using ev_ref(loop) and ev_run(loop).
> Now, I want to add watcher for EV_READ event to this loop on the fly as and
> when
> an event comes for EV_ASYNC.
> Is it possible to do so ?

You can add watchers at any time when libev itself isn't executing. For
example, from inside an ev_async callback (but why would you need ev_ref when
you already have an ev_async watcher registered?).

When using threads, you can provide your own mutex functions to lock libev's
internal data, which makes it possible to add watchers even when the event
loop itself is blocked. See the "thread locking example" in the docs for

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

More information about the libev mailing list