using libev with multiple threads

Tony Arcieri tony.arcieri at gmail.com
Sun Feb 3 22:30:22 CET 2013


Hello there,

I use libev as part of a multithreaded system in Ruby called Celluloid::IO.
libev itself is specifically wrapped by this gem, which provides a
cross-platform wrapper between CRubies (which use libev) and JRuby (which
uses Java NIO):

https://github.com/tarcieri/nio4r

I can't say I've been as diligent about identical semantics across
platforms as Marc has with libev, but I've been working to fix problems
with differing semantics as they're discovered.

nio4r is modeled after Java NIO Selectors. The JVM uses a pipe-per-selector
to implement a method it calles "wakeup" which allows one thread to wake up
another. This is similar to libev async watchers, but for whatever reason
I've always encountered segfaults with async watchers and just use an IO
watcher with a pipe ;)

Celluloid itself is a multithreading library, and Celluloid::IO provides
the I/O component. Every thread that uses Celluloid::IO has its own libev
loop, and the wakeup mechanism (i.e. writing to a pipe) is used to send
messages to a thread which is blocking on a libev loop.

It's working quite well and people can create as many Celluloid::IO actors
as they have file descriptors for the wakeup pipes.

-- 
Tony Arcieri
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.schmorp.de/pipermail/libev/attachments/20130203/43b7f19c/attachment.html>


More information about the libev mailing list