Function std.parallelism.scopedTask
These functions allow the creation of Task
objects on the stack rather
than the GC heap. The lifetime of a Task
created by scopedTask
cannot exceed the lifetime of the scope it was created in.
auto scopedTask(alias fun, Args...)
(
Args args
);
auto scopedTask(F, Args...)
(
scope 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);
scopedTask
might be preferred over task
:
1. When a Task
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 scopedTask
takes a scope
delegate.
2. As a micro-optimization, to avoid the heap allocation associated with
task
or with the creation of a closure.
Usage is otherwise identical to task
.
Notes
Task
objects created using scopedTask
will automatically
call Task
in their destructor if necessary to ensure
the Task
is complete before the stack frame they reside on is destroyed.