Patch: fix libeio cancellation

Hongli Lai hongli at
Mon Aug 18 21:32:58 CEST 2014

On Mon, Aug 18, 2014 at 8:33 PM, james <james at> wrote:
> Why not call it yourself, when you cancel?

Mainly because of reason 1. If the open() system call has already
finished, then libeio is the only thing that knows what the file
descriptor is. The calling code has no way of knowing what the file
descriptor is, and thus no way to clean up the file descriptor.

Furthermore, even if reason 1 does not hold, I still cannot safely
call the callback myself, because of race conditions. The libeio
thread might not have seen my cancellation flag (e.g. due to compiler
optimizations, CPU instruction reordering, lack of memory barriers,
etc) and might be about to call my callback. This will result in my
callback being called twice. This can be solved my making callbacks
idempotent, but - in line with reason 2 - it increases the complexity
of the calling codebase by introducing new code paths.

Phusion | Web Application deployment, scaling, and monitoring solutions

E-mail: info at
Chamber of commerce no: 08173483 (The Netherlands)

More information about the libev mailing list