task_group#
[scheduler.task_group]
A task_group represents the concurrent execution of a group of tasks.
You can dynamically add tasks to the group while it is executing.
The thread executing task_group::wait() might participate in other tasks that
are not related to the particular task_group.
// Defined in header <oneapi/tbb/task_group.h>
namespace oneapi {
namespace tbb {
    class task_group {
    public:
        task_group();
        task_group(task_group_context& context);
        ~task_group();
        template<typename Func>
        void run(Func&& f);
        template<typename Func>
        task_handle defer(Func&& f);
        void run(task_handle&& h);
        template<typename Func>
        task_group_status run_and_wait(const Func& f);
        task_group_status run_and_wait(task_handle&& h);
        task_group_status wait();
        void cancel();
    };
    bool is_current_task_group_canceling();
} // namespace tbb
} // namespace oneapi
Member functions#
- 
task_group()#
 Constructs an empty
task_group.
- 
task_group(task_group_context &context)#
 Constructs an empty
task_group. All tasks added into thetask_groupare associated with thecontext.
- 
~task_group()#
 Destroys the
task_group.Requires: Method
waitmust be called before destroying atask_group, otherwise, the destructor throws an exception.
- 
template<typename F>
task_handle defer(F &&f)# Creates a deferred task to compute
f()and returnstask_handlepointing to it.The task is not scheduled for the execution until it is explicitly requested, for example, with the
task_group::runmethod. However, the task is still added into thetask_group, thus thetask_group::waitmethod waits until thetask_handleis either scheduled or destroyed.The
Ftype must meet the Function Objects requirements described in the [function.objects] section of the ISO C++ standard.Returns:
task_handleobject pointing to a task to computef().
- 
template<typename Func>
void run(Func &&f)# Adds a task to compute
f()and returns immediately. TheFunctype must meet the Function Objects requirements described in the [function.objects] section of the ISO C++ standard.
- 
void run(task_handle &&h)#
 Schedules the task object pointed by the
hfor the execution.Note
- The failure to satisfy the following conditions leads to undefined behavior:
 his not empty.*thisis the sametask_groupthathis created with.
- 
template<typename Func>
task_group_status run_and_wait(const Func &f)# Equivalent to
{run(f); return wait();}. TheFunctype must meet the Function Objects requirements described in the [function.objects] section of the ISO C++ standard.Returns: The status of
task_group. See task_group_status.
- 
task_group_status wait()#
 Waits for all tasks in the group to complete or be cancelled.
Returns: The status of
task_group. See task_group_status.
- 
void cancel()#
 Cancels all tasks in this
task_group.
Non-member functions#
- 
bool is_current_task_group_canceling()#
 Returns true if an innermost
task_groupexecuting on this thread is cancelling its tasks.