View source code
Display the source code in std/parallelism.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

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.yieldForce in their destructor if necessary to ensure the Task is complete before the stack frame they reside on is destroyed.

Authors

License

Boost License 1.0