1.. _task_group_extensions: 2 3task_group extensions 4===================== 5 6.. note:: 7 To enable these extensions, set the ``TBB_PREVIEW_TASK_GROUP_EXTENSIONS`` macro to 1. 8 9.. contents:: 10 :local: 11 :depth: 1 12 13Description 14*********** 15 16|full_name| implementation extends the `tbb::task_group specification <https://spec.oneapi.com/versions/latest/elements/oneTBB/source/task_scheduler/task_group/task_group_cls.html>`_ with the following members: 17 18 - Constructor that takes a custom ``tbb::task_group_context`` object as an argument. 19 - Methods to create and run deferred tasks with ``task_handle``. 20 - Requirements for a user-provided function object. 21 22 23API 24*** 25 26Header 27------ 28 29.. code:: cpp 30 31 #include <oneapi/tbb/task_group.h> 32 33Synopsis 34-------- 35 36.. code:: cpp 37 38 namespace oneapi { 39 namespace tbb { 40 41 class task_group { 42 public: 43 task_group(task_group_context& context); 44 45 template<typename F> 46 task_handle defer(F&& f); 47 48 void run(task_handle&& h); 49 50 //only F return type requirements have changed 51 template<typename F> 52 void run(F&& f); 53 }; 54 55 } // namespace tbb 56 } // namespace oneapi 57 58Member Functions 59---------------- 60 61.. cpp:function:: task_group(task_group_context& context) 62 63Constructs an empty ``task_group``, which tasks are associated with the ``context``. 64 65.. cpp:function:: template<typename F> task_handle defer(F&& f) 66 67Creates a deferred task to compute ``f()`` and returns ``task_handle`` pointing to it. 68 69The task is not scheduled for execution until explicitly requested. For example, with the ``task_group::run`` method. 70However, the task is still added into the ``task_group``, thus the ``task_group::wait`` method waits until the ``task_handle`` is either scheduled or destroyed. 71 72The ``F`` type must meet the `Function Objects` requirements described in the [function.objects] section of the ISO C++ Standard. 73 74As an optimization hint, ``F`` might return a ``task_handle``, which task object can be executed next. 75 76.. note:: 77 The ``task_handle`` returned by the function must be created with ``*this`` ``task_group``. It means, with the one for which run method is called, otherwise it is an undefined behavior. 78 79**Returns:** ``task_handle`` object pointing to task to compute ``f()``. 80 81.. cpp:function:: void run(task_handle&& h) 82 83Schedules the task object pointed by the ``h`` for execution. 84 85.. note:: 86 The failure to satisfy the following conditions leads to undefined behavior: 87 * ``h`` is not empty. 88 * ``*this`` is the same ``task_group`` that ``h`` is created with. 89 90.. cpp:function:: template<typename F> void run(F&& f) 91 92As an optimization hint, ``F`` might return a ``task_handle``, which task object can be executed next. 93 94.. note:: 95 The ``task_handle`` returned by the function must be created with ``*this`` ``task_group``. It means, with the one for which run method is called, otherwise it is an undefined behavior. 96 97 98.. rubric:: See also 99 100* `oneapi::tbb::task_group specification <https://spec.oneapi.com/versions/latest/elements/oneTBB/source/task_scheduler/task_group/task_group_cls.html>`_ 101* `oneapi::tbb::task_group_context specification <https://spec.oneapi.com/versions/latest/elements/oneTBB/source/task_scheduler/scheduling_controls/task_group_context_cls.html>`_ 102* :doc:`oneapi::tbb::task_handle class <task_group_extensions/task_handle>` 103