core.thread.fiber.base

Base fiber module provides OS-indepedent part of lightweight threads aka fibers.

Types 1

This class provides a cooperative concurrency mechanism integrated with the threading and garbage collection functionality. Calling a fiber may be considered a blocking operation that returns when the fiber yields (via Fiber.yield()). Execution occurs within the context of the calling thread so synchronization is not necessary to guarantee memory visibility so long as the same thread calls the fiber each time. Please note that there is no requirement that a fiber be bound to one specific thread. Rather, fibers may be freely passed between threads so long as they are not currently executing. Like threads, a new fiber thread may be created using either derivation or composition, as in the following example.

Warning: Status registers are not saved by the current implementations. This means floating point exception status bits (overflow, divide by 0), rounding mode and similar stuff is set per-thread, not per Fiber!

Warning: On ARM FPU registers are not saved if druntime was compiled as ARM_SoftFloat. If such a build is used on a ARM_SoftFP system which actually has got a FPU and other libraries are using the FPU registers (other code is compiled as ARM_SoftFP) this can cause problems. Druntime must be compiled as ARM_SoftFP in this case.

Authors

Based on a design by Mikola Lysenko.
Fields
Callable m_call
bool m_isRunning
Throwable m_unhandled
State m_state
StackContext * m_ctxt
size_t m_size
void * m_pmem
FiberBase sm_this
Methods
Throwable call( Rethrow rethrow = Rethrow.yes )Transfers execution to this fiber object. The calling context will be suspended until the fiber calls Fiber.yield() or until it terminates via an unhandled exception.
Throwable call( Rethrow rethrow )()ditto
private void callImpl() nothrow @nogc
void reset() nothrow @nogcResets this fiber so that it may be re-used, optionally with a new function/delegate. This routine should only be called for fibers that have terminated, as doing otherwise could result in scope-d...
void reset( void function() fn ) nothrow @nogcditto
void reset( void delegate() dg ) nothrow @nogcditto
State state() @property const @safe pure nothrow @nogcGets the current state of this fiber.
void yield() nothrow @nogcForces a context switch to occur away from the calling fiber.
void yieldAndThrow( Throwable t ) nothrow @nogcForces a context switch to occur away from the calling fiber and then throws obj in the calling fiber.
FiberBase getThis() @safe nothrow @nogcProvides a reference to the calling fiber or null if no fiber is currently active.
void run()
void allocStack( size_t sz, size_t guardPageSize ) nothrow;
void freeStack() nothrow @nogc
void initStack() nothrow @nogc
void setThis( FiberBase f ) nothrow @nogc
void switchIn() nothrow @nogc
void switchOut() nothrow @nogc
Constructors
this( void function() fn, size_t sz, size_t guardPageSize )Initializes a fiber object which is associated with a static D function.
this( void delegate() dg, size_t sz, size_t guardPageSize )Initializes a fiber object which is associated with a dynamic D function.
Destructors
~thisCleans up any remaining resources used by this object.
Nested Templates
RethrowFlag to control rethrow behavior of call
StateA fiber may occupy one of three states: HOLD, EXEC, and TERM.

Functions 1

fnvoid fiber_entryPoint() nothrow