Creates a Condition variable analog for signaling.
Assigns a logical thread to execute the supplied op.
Spawns the supplied op and starts the Scheduler.
Yields execution to another logical thread.
Returns an appropriate ThreadInfo instance.
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.
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.