A structured_task_group is like a task_group, but has only a subset of the functionality. It may permit performance optimizations in the future. The restrictions are:
The function fork_join below evaluates f1() and f2(), in parallel if resources permit.
#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); // spawn a task
task_handle<Func2> h2(f2);
group.run(h2); // spawn another task
group.wait(); // wait for both tasks to complete
// 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>
void run_and_wait( task_handle<Func>& handle );
task_group_status wait();
bool is_canceling();
void cancel();
};
}