Module std.parallelism
std implements high-level primitives for SMP parallelism.
These include parallel foreach, parallel reduce, parallel eager map, pipelining
and future/promise parallelism.  std is recommended when the
same operation is to be executed in parallel on different data, or when a
function is to be executed in a background thread and its result returned to a
well-defined main thread.  For communication between arbitrary threads, see
std.
std is based on the concept of a Task.  A Task is an
object that represents the fundamental unit of work in this library and may be
executed in parallel with any other Task.  Using Task
directly allows programming with a future/promise paradigm.  All other
supported parallelism paradigms (parallel foreach, map, reduce, pipelining)
represent an additional level of abstraction over Task.  They
automatically create one or more Task objects, or closely related types
that are conceptually identical but not part of the public API.
After creation, a Task may be executed in a new thread, or submitted
to a TaskPool for execution.  A TaskPool encapsulates a task queue
and its worker threads.  Its purpose is to efficiently map a large
number of Tasks onto a smaller number of threads.  A task queue is a
FIFO queue of Task objects that have been submitted to the
TaskPool and are awaiting execution.  A worker thread is a thread that
is associated with exactly one task queue.  It executes the Task at the
front of its queue when the queue has work available, or sleeps when
no work is available.  Each task queue is associated with zero or
more worker threads.  If the result of a Task is needed before execution
by a worker thread has begun, the Task can be removed from the task queue
and executed immediately in the thread where the result is needed.
Warning
Unless marked as @trusted or @safe, artifacts in
          this module allow implicit data sharing between threads and cannot
          guarantee that client code is free from low level data races.
Author
David Simcha
Example
import stdFunctions
| Name | Description | 
|---|---|
| 
									defaultPoolThreads(newVal)
								 | These properties get and set the number of worker threads in the TaskPoolinstance returned bytaskPool.  The default value istotalCPUs- 1.
Calling the setter after the first call totaskPooldoes not changes
number of worker threads in the instance returned bytaskPool. | 
| 
									parallel(range)
								 | Convenience functions that forwards to taskPool.  The
purpose of these is to make parallel foreach less verbose and more
readable. | 
| 
									scopedTask(args)
								 | These functions allow the creation of Taskobjects on the stack rather
than the GC heap.  The lifetime of aTaskcreated byscopedTaskcannot exceed the lifetime of the scope it was created in. | 
| 
									task(args)
								 | Creates a Taskon the GC heap that calls an alias.  This may be executed
viaTaskor by submitting to aTaskPool.  A globally accessible instance ofTaskPoolis provided bytaskPool. | 
| 
									task(delegateOrFp, args)
								 | Creates a Taskon the GC heap that calls a function pointer, delegate, or
class/struct with overloaded opCall. | 
| 
									task(fun, args)
								 | Version of taskusable from@safecode.  Usage mechanics are
identical to the non-@safe case, but safety introduces some restrictions: | 
| 
									taskPool()
								 | Returns a lazily initialized global instantiation of TaskPool.
This function can safely be called concurrently from multiple non-worker
threads.  The worker threads in this pool are daemon threads, meaning that it
is not necessary to callTaskPoolorTaskPoolbefore
terminating the main thread. | 
Classes
| Name | Description | 
|---|---|
| 
									TaskPool
								 | This class encapsulates a task queue and a set of worker threads.  Its purpose
is to efficiently map a large number of Tasks onto a smaller number of
threads.  A task queue is a FIFO queue ofTaskobjects that have been
submitted to theTaskPooland are awaiting execution.  A worker thread is a
thread that executes theTaskat the front of the queue when one is
available and sleeps when the queue is empty. | 
Structs
| Name | Description | 
|---|---|
| 
									Task
								 | Taskrepresents the fundamental unit of work.  ATaskmay be
executed in parallel with any otherTask.  Using this struct directly
allows future/promise parallelism.  In this paradigm, a function (or delegate
or other callable) is executed in a thread other than the one it was called
from.  The calling thread does not block while the function is being executed.
A call toworkForce,yieldForce, orspinForceis used to
ensure that theTaskhas finished executing and to obtain the return
value, if any.  These functions anddonealso act as full memory barriers,
meaning that any memory writes made in the thread that executed theTaskare guaranteed to be visible in the calling thread after one of these functions
returns. | 
Aliases
| Name | Type | Description | 
|---|---|---|
| totalCPUs | __lazilyInitializedConstant!(immutable(uint),(uint).max,totalCPUsImpl) | The total number of CPU cores available on the current machine, as reported by the operating system. |