Report a bugIf you spot a problem with this page, click here to create a Bugzilla issue.
Improve this pageQuickly fork, edit online, and submit a pull request for this page.Requires a signed-in GitHub account. This works well for small changes.If you'd like to make larger changes you may want to consider usinga local clone.
core.thread.fiber
The fiber module provides lightweight threads aka fibers.
Authors:Sean Kelly, Walter Bright, Alex Rønne Petersen, Martin Nowak
package nothrow @nogc void
fiber_switchContext(void**
oldp, void*
newp);
class
Fiber:
core.thread.fiber.base.FiberBase;
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.
WarningStatus 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!
WarningOn 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.
enum int
defaultStackPages;
nothrow this(void function()
fn, size_t
sz = pageSize * defaultStackPages, size_t
guardPageSize = pageSize);
Initializes a fiber object which is associated with a static D function.
Parameters:void function()fn | The fiber function. |
size_tsz | The stack size for this fiber. |
size_tguardPageSize | size of the guard page to trap fiber's stack overflows. Beware that using this will increase the number of mmaped regions on platforms using mmap so an OS-imposed limit may be hit. |
nothrow this(void delegate()
dg, size_t
sz = pageSize * defaultStackPages, size_t
guardPageSize = pageSize);
Initializes a fiber object which is associated with a dynamic D function.
Parameters:void delegate()dg | The fiber function. |
size_tsz | The stack size for this fiber. |
size_tguardPageSize | size of the guard page to trap fiber's stack overflows. Beware that using this will increase the number of mmaped regions on platforms using mmap so an OS-imposed limit may be hit. |
static nothrow @nogc @safe Fiber
getThis();
Provides a reference to the calling fiber or null if no fiber is currently active.
Returns:The fiber object representing the calling fiber or null if no fiber is currently active within this thread. The result of deleting this object is undefined.
protected final nothrow void
allocStack(size_t
sz, size_t
guardPageSize);