task_group
[scheduler.task_group]
task_group は、同時に実行するタスクのグループを表します。タスクは実行とともに動的にグループに追加されます。task_group::wait() を実行するスレッドは、特定の task_group に関連しない他のタスクに参加する可能性があります。
// <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メンバー関数
- task_group()
空の
task_groupを構築。
- task_group(task_group_context &context)
空の
task_groupを構築。task_groupに追加されたすべてのタスクは、contextに関連付けられます。
- ~task_group()
task_groupを破棄します。要件:
waitメソッドはtask_groupを破棄する前に呼び出さなければなりません。そうしないとデストラクターが例外をスローします。
- template<typename F>
task_handle defer(F &&f) f()を計算する遅延タスクを作成し、それを指すtask_handleを返します。タスクは、
task_group::runメソッドなどを使用して明示的に要求されるまで実行はスケジュールされません。ただし、タスクはtask_groupに引き続いて追加されるため、task_group::waitメソッドはtask_handleがスケジュールされるか破棄されるまで待機します。Fタイプは、[function.objects] ISO C++ 標準の関数オブジェクトの要件を満たしている必要があります。戻り値:
f()を計算するタスクを指すtask_handleオブジェクトを返します。
- template<typename Func>
void run(Func &&f) f()を計算するタスクを追加して直ちにリターンします。Funcタイプは、[function.objects] ISO C++ 標準の関数オブジェクトの要件を満たしている必要があります。
- void run(task_handle &&h)
hで指定されたタスク・オブジェクトの実行をスケジュールします。注
- 次の条件が満たされないと未定義の動作となります。
hが空ではない。*thisの生成に使用したtask_groupと同じである。
- template<typename Func>
task_group_status run_and_wait(const Func &f) {run(f); return wait();}と等価です。Funcタイプは、[function.objects] ISO C++ 標準の関数オブジェクトの要件を満たしている必要があります。戻り値:
task_groupのステータスを返します。task_group_status を参照してください。
- task_group_status wait()
グループのすべてのタスクが完了する、またはキャンセルされるのを待ちます。
戻り値:
task_groupのステータスを返します。task_group_status を参照してください。
- void cancel()
この
task_groupのすべてのタスクをキャンセルします。
非メンバー関数
- bool is_current_task_group_canceling()
このスレッドの最も内側の
task_groupがタスクをキャンセルしている場合は true を返します。
