The OpenD Programming Language

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.

Members

Functions

newCondition
Condition newCondition(Mutex m)

Creates a Condition variable analog for signaling.

spawn
void spawn(void delegate() op)

Assigns a logical thread to execute the supplied op.

start
void start(void delegate() op)

Spawns the supplied op and starts the Scheduler.

yield
void yield()

Yields execution to another logical thread.

Properties

thisInfo
ThreadInfo thisInfo [@property getter]

Returns an appropriate ThreadInfo instance.

Examples

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.

Meta