Is it safe to call ev_feed_event on an ev_timer in different thread?

Marc Lehmann schmorp at
Mon Aug 27 06:50:49 CEST 2012

On Sun, Aug 26, 2012 at 09:55:42PM +0800, 钱晓明 <mailtoantares at> wrote:
> Hi, is ev_feed_event is thread safe?

As long as you call it on the same loop only in one thread at a time, yes.

> I have an ev_timer installed in a loop within main thread, can I call
> ev_feed_event in another thread to simulate the time out event?

Not without locking the event loop, e.g. with a mutex (you could use the
acquire/release callbacks and an ev_async watcher to lock/unlock and wake
up the loop).

> Is it safe?

Without proper locking, no, it will most likely corrupt libev's internal
data structures and not even work.

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

More information about the libev mailing list