[concurrency-interest] Fast control transfer from one thread to another?
Charles Oliver Nutter
headius at headius.com
Mon Aug 8 15:08:08 EDT 2011
I'm looking to improve the performance of JRuby's implementation of
Ruby's "Fiber". Fiber is intended as a lightweight thread or
coroutine. Fibers are bound to a parent thread, and only one Fiber or
the parent thread can be running at a given time. Control transfer --
in the logical sense -- pauses the caller and continues the callee
from where it left off. The callee can then "yield" control back to
the caller, pausing its execution.
Because Fibers retain execution state (call stack, etc), they are
implemented in JRuby using a native thread per Fiber. Control transfer
used to be done via SynchronousBlockingQueue objects, but I am making
changes to use LockSupport.park/unpark directly. LockSupport appears
to transfer control around 2x faster than using SBQ, but it's still
many times slower than C Ruby's mechanism of saving and restoring
native C stack frames within the same native thread.
So, I'm looking for suggestions on a better mechanism to explicitly
deschedule one thread and start another one, knowing that it's always
an explicit cooperative rescheduling.
More information about the Concurrency-interest