Background


Interruption API

This problem isn’t new to fibers. On the thread domain the usual approaches are:

I’ve spent long hours researching before settling down on a single design. The chosen design mainly borrows from POSIX thread cancellation API and Boost.Thread.

Other inspirations, even if minimal, were:

As for the interrupter traits (used in this_fiber.with_intr()), I didn’t allow a stateful trait object because this object would be moved across the stages of the async operation and the user would stay unable to extract this info at the fiber wakeup anyway. If the user will have to resort to heap usage one way or another, he might just as well use fiber local storage and at least reuse these memory regions across async calls.

Fiber local storage

Boost.Fiber interface was not considered. Boost.Fiber just mirrors Boost.Thread interface. However Boost.Thread interface is meant for portability on platforms that lack support for thread-local. If the implementation is not constrained to rely solely on pthread_key_create/tss_create then there is no reason to follow Boost.Thread design.

IOFiber design is similar to Facebook’s Folly. The difference is support for user types that have no default constructors.