using libev with multiple threads

Chris Herssens chris.herssens at gmail.com
Thu Jan 31 15:31:01 CET 2013


I want to use libev with multiple threads for the handling of tcp
connections. What I want to is:

   1.

   The main thread listen on incoming connections, accept the connections
   and forward the connection to a workerthread.
   2.

   I have a pool of workerthreads. The number of threads depends on the
   number of cpu's. Each worker-thread has an event loop. The worker-thread
   listen if I can write on the tcp socket or if somethings available for
   reading.

I looked into the documentation of libev and I known this can be done with
libev, but I can't find any example how I have to do that.
Does someone has an example? I think that I have to use the ev_loop_new()
api, for the worker-threads and for the main thread I have to use the
ev_default_loop() ?

Since I new in using libev I really need an example how to dispatch an
incoming tcp connection to a worker-thread. I have started to implement it,
but I don't get it work. In the main thread I start the default loop. And
if I received new connection I create a watcher and use the ev_io_start
with the loop that I create in the workerthread. It seems that the callback
function of the watcher is not always triggered.  Also Is there a way to
block the ev_loop if there no active watchers ?


regards.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.schmorp.de/pipermail/libev/attachments/20130131/0a4a7ba7/attachment.html>


More information about the libev mailing list