View source code Display the source code in std/concurrency.d from which this page was generated on github. 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. Page wiki View or edit the community-maintained wiki page associated with this page.

std.concurrency.scheduler - multiple declarations

Variable scheduler

Sets the Scheduler behavior within the program.

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.

Declaration

Scheduler scheduler;

Interface Scheduler

A Scheduler controls how threading is performed by spawn.

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.

Properties

Name Type Description
thisInfo [get] ThreadInfo Returns an appropriate ThreadInfo instance.

Methods

Name Description
newCondition Creates a Condition varialbe analog for signaling.
spawn Assigns a logical thread to execute the supplied op.
start Spawns the supplied op and starts the Scheduler.
yield Yields execution to another logical thread.

Example

import std.concurrency;
import std.stdio;

void main()
{
    scheduler = new FiberScheduler;
    scheduler.start(
    {
        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.

Authors

Sean Kelly, Alex Rønne Petersen, Martin Nowak

License

Boost License 1.0.

Comments