hpx::experimental::task_block

hpx::experimental::task_block#

Defined in header hpx/task_block.hpp.

See Public API for a list of names and headers that are part of the public HPX API.

See also:

template<typename ExPolicy = hpx::execution::parallel_policy>
class task_block#

The class task_block defines an interface for forking and joining parallel tasks. The define_task_block and define_task_block_restore_thread function templates create an object of type task_block and pass a reference to that object to a user-provided callable object.

An object of class task_block cannot be constructed, destroyed, copied, or moved except by the implementation of the task region library. Taking the address of a task_block object via operator& or addressof is ill formed. The result of obtaining its address by any other means is unspecified.

A task_block

is active if it was created by the nearest enclosing task block, where “task block” refers to an invocation of define_task_block or define_task_block_restore_thread and “nearest

enclosing” means the most recent invocation that has not yet completed. Code designated for execution in another thread by means other than the facilities in this section (e.g., using thread or async) are not enclosed in the task region and a

task_block passed to (or captured by) such code is not active within that code. Performing any operation on a task_block that is not active results in undefined behavior.

The task_block that is active before a specific call to the run member function is not active within the asynchronous function that invoked run. (The invoked function should not, therefore, capture the task_block from the surrounding block.)

Example:
   define_task_block([&](auto& tr) {
       tr.run([&] {
           tr.run([] { f(); });              // Error: tr is not active
           define_task_block([&](auto& tr) { // Nested task block
               tr.run(f);                    // OK: inner tr is active
               /// ...
           });
       }); /// ...
   });
Template Parameters:

ExPolicy – The execution policy an instance of a task_block was created with. This defaults to parallel_policy.