View source code
Display the source code in std/concurrency.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly 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 using local clone.

std.concurrency.Scheduler/scheduler - multiple declarations

Variable scheduler

Sets the Scheduler behavior within the program.

Scheduler scheduler ;

This variable sets the Scheduler behavior within this program. Typically, when setting a Scheduler, scheduler.start() should be called in main. This routine will not return until program execution is complete.

Interface Scheduler

A Scheduler controls how threading is performed by spawn.

interface Scheduler ;

Implementing a Scheduler allows the concurrency mechanism used by this module to be customized according to different needs. By default, a call to spawn will create a new kernel thread that executes the supplied routine and terminates when finished. But it is possible to create Schedulers that reuse threads, that multiplex Fibers (coroutines) across a single thread, or any number of other approaches. By making the choice of Scheduler a user-level option, std.concurrency may be used for far more types of application than if this behavior were predefined.


thisInfo[get] ThreadInfoReturns an appropriate ThreadInfo instance.


newCondition (m) Creates a Condition variable analog for signaling.
spawn (op) Assigns a logical thread to execute the supplied op.
start (op) Spawns the supplied op and starts the Scheduler.
yield () Yields execution to another logical thread.


import std.concurrency;
import std.stdio;

void main()
    scheduler = new FiberScheduler;
        writeln("the rest of main goes here");

Some schedulers have a dispatching loop that must run if they are to work properly, so for the sake of consistency, when using a scheduler, start() must be called within main(). This yields control to the scheduler and will ensure that any spawned threads are executed in an expected manner.


Sean Kelly, Alex Rønne Petersen, Martin Nowak


Boost License 1.0.