structured_task_group Class


This feature is deprecated and will be removed in the future.


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:

  • Methods run and run_and_wait take only task_handle arguments, not general functors.
  • Methods run and run_and_wait do not copy their task_handle arguments. The caller must not destroy those arguments until after wait or run_and_wait returns.
  • Methods run, run_and_wait, cancel, and wait should be called only by the thread that created the structured_task_group.
  • Method wait (or run_and_wait) should be called only once on a given instance of structured_task_group.


The function fork_join below evaluates f1() and f2(), in parallel if resources permit.

#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);; // spawn a task

    tbb::task_handle<Func2> h2(f2);; // spawn another task

    group.wait(); // wait for both tasks to complete
    // now safe to destroy h1 and h2


namespace tbb {
    class 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();
For more complete information about compiler optimizations, see our Optimization Notice.