An example Scheduler using `Fiber`s.
A Generator is a Fiber that periodically returns values of type T to the caller via yield. This is represented as an InputRange.
Thrown if a linked thread has terminated.
Thrown on mailbox crowding if the mailbox is configured with OnCrowding.throwException.
Thrown on calls to receiveOnly if a message other than the type the receiving thread expected is sent.
Thrown on calls to receive if the thread that spawned the receiving thread has terminated and no more messages exist.
Thrown if a message was sent to a thread via std.concurrency.prioritySend and the receiver does not have a handler for a message of this type.
An example Scheduler using kernel threads.
Thrown when a Tid is missing, e.g. when ownerTid doesn't find an owner thread.
These behaviors may be specified when a mailbox is full.
Initializes var with the lazy init value in a thread-safe manner.
Same as above, but takes a separate mutex instead of sharing one among all initOnce instances.
Gets the Tid associated with name.
Places the values as a message on the front of tid's message queue.
Receives a message from another thread.
Receives only messages with arguments of the specified types.
Receives a message from another thread and gives up if no match arrives within a specified duration.
Associates name with tid.
Places the values as a message at the back of tid's message queue.
Sets a maximum mailbox size.
Sets a maximum mailbox size.
* Starts fn(args) in a new logical thread. * * Executes the supplied function in a new logical thread represented by * Tid. The calling thread is designated as the owner of the new thread. * When the owner thread terminates an OwnerTerminated message will be * sent to the new thread, causing an OwnerTerminated exception to be * thrown on receive(). * * Params: * fn = The function to execute. * args = Arguments to the function. * * Returns: * A Tid representing the new logical thread. * * Notes: * args must not have unshared aliasing. In other words, all arguments * to fn must either be shared or immutable or have no * pointer indirection. This is necessary for enforcing isolation among * threads. * * Similarly, if fn is a delegate, it must not have unshared aliases, meaning * fn must be either shared or immutable.
Starts fn(args) in a logical thread and will receive a LinkTerminated message when the operation terminates.
Removes the registered name associated with a tid.
If the caller is a Fiber and is not a Generator, this function will call scheduler.yield() or Fiber.yield(), as appropriate.
Yields a value of type T to the caller of the currently executing generator.
A Scheduler controls how threading is performed by spawn.
Return the Tid of the thread which spawned the caller's thread.
Sets the Scheduler behavior within the program.
Encapsulates all implementation-level data needed for scheduling.
An opaque type used to represent a logical thread.
<a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>.
Copyright Sean Kelly 2009 - 2014.
This is a low-level messaging API upon which more structured or restrictive APIs may be built. The general idea is that every messageable entity is represented by a common handle type called a Tid, which allows messages to be sent to logical threads that are executing in both the current process and in external processes using the same interface. This is an important aspect of scalability because it allows the components of a program to be spread across available resources with few to no changes to the actual implementation.
A logical thread is an execution context that has its own stack and which runs asynchronously to other logical threads. These may be preemptively scheduled kernel threads, fibers (cooperative user-space threads), or some other concept with similar behavior.
The type of concurrency used when logical threads are created is determined by the Scheduler selected at initialization time. The default behavior is currently to create a new kernel thread per call to spawn, but other schedulers are available that multiplex fibers across the main thread or use some combination of the two approaches.