Fwd: need some detail about ev_async.

Zsbán Ambrus ambrus at math.bme.hu
Mon Nov 21 22:11:40 CET 2011


2011/11/21 马承珂 <fatmck at 163.com>:
> I want to use ev_async to implement the "tell" work, so I want to know is
> there any mutext or lock in ev_async functions? will a thread be blocked
> when calling ev_async functions? what low-level api does ev_async used on
> Linux platform?

On Linux, ev_async_send sets a flag and then writes to an eventfd.
This means the ev_async_send call definitely should not block: no lock
in user-space is involved and the write call in the kernel should not
block.

On Linux kernels older than 2.6.22 and on all non-Linux systems (I
believe), eventfd is not supported.  I think this implementation can
block if the pipe is full, which could happen eg. if you are calling
ev_async_send many times (even on different ev_async watchers).  In
recent (yet to be released, libev-4.09) versions of libev, this write
to the pipe is guarded by some flag construction, which might have the
effect that in such versions the pipe write won't block, but I don't
know if it does.  I guess schmorp can answer this.  Frankly, I don't
know much about SMP and don't even understand whether that new flag
construction must work reliably (that is, can't cause the event loop
to miss an async send event).

Ambrus



More information about the libev mailing list