std.concurrency.Scheduler/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
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 Scheduler
s that
reuse threads, that multiplex Fiber
s (coroutines) across a single thread,
or any number of other approaches. By making the choice of Scheduler
a
user-level option, std
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
(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. |
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