structured_task_group は task_group に似ていますが、一部の機能しか含まれていません。この制限は、将来のパフォーマンスの最適化のためです。制限は次のとおりです。
下記の fork_join 関数は、リソースさえ許せば f1() と f2() を並列に評価します。
#include "tbb/task_group.h"
using namespace tbb;
template<typename Func1, typename Func2>
void fork_join( const Func1& f1, const Func2& f2 ) {
structured_task_group group;
task_handle<Func1> h1(f1);
group.run(h1); // タスクを作成
task_handle<Func2> h2(f2);
group.run(h2); // 別のタスクを作成
group.wait(); // 両方のタスクが完了するのを待つ
// h1 と h2 を破棄しても安全
}
namespace tbb {
class structured_task_group {
public:
structured_task_group();
~structured_task_group();
template<typename Func>
void run( task_handle<Func>& handle );
template<typename Func>
void run_and_wait( task_handle<Func>& handle );
task_group_status wait();
bool is_canceling();
void cancel();
};
}