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