# structured_task_group Class

## Description

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`.

## Example

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
        }

## Members

     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();
            };
        }

Parent topic: Task Groups

## See Also

task_handle Template Class
task_group Class