Function std.parallelism.scopedTask
These functions allow the creation of
objects on the stack rather
than the GC heap. The lifetime of a Task
created by Task
cannot exceed the lifetime of the scope it was created in.
scopedTask
might be preferred over scopedTask
:
task
1. When a
that calls a delegate is being created and a closure
cannot be allocated due to objects on the stack that have scoped
destruction. The delegate overload of Task
takes a scopedTask
scope
delegate.
2. As a micro-optimization, to avoid the heap allocation associated with
or with the creation of a closure.
task
Usage is otherwise identical to
.
task
Prototypes
auto scopedTask(alias fun, Args...)( Args args ); auto scopedTask(F, Args...)( F delegateOrFp, Args args ) if (is(typeof(delegateOrFp(args))) && !isSafeTask!F); auto scopedTask(F, Args...)( F fun, Args args ) @trusted if (is(typeof(fun(args))) && isSafeTask!F);
Notes
objects created using Task
will automatically
call scopedTask
in their destructor if necessary to ensure
the Task.yieldForce
is complete before the stack frame they reside on is destroyed.
Task