libev out of context thread

Marc Lehmann schmorp at
Thu Dec 12 11:57:02 CET 2013

On Thu, Dec 12, 2013 at 10:12:57AM +1100, Varun Chandramohan <cvaruneng04 at> wrote:
> Thanks for the reply. Not sure why the code formatting is weird. I started
> using async watchers and it helped. I got it working with that.

Just keep in mind that ev_async_send is the only function you are allowed to
call cuncorrently from multiple threads :)

> remove one other thread as I felt it was not needed with async watcher.
> My solution is to use thread 1 to read from socket a packet add it to queue
> and immediately notify the async watcher of data available. I also added
> mutex lock to avoid race condition. Everything seem to be working well
> as expected. I have currently put the code under stress test. Thanks for
> the help.

Sounds cool. I forgot to mention that the EV::Loop::Async module is a
working example of this technique as well, using mutexes to protect the
loop and using async watchers to wake up the event loop to take note of
any changes.

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

More information about the libev mailing list