# tbb::task_group_context Class Reference
[Task Scheduling]

Used to form groups of tasks. More...

`#include <parallel_invoke.h>`

List of all members.

## Public Types

enum | kind_type { isolated, bound }
enum | traits_type { exact_exception = 0x0001ul << traits_offset, concurrent_wait = 0x0004ul << traits_offset, default_traits }

## Public Member Functions

| task_group_context (kind_type relation_with_parent=bound, uintptr_t traits=default_traits)
| Default & binding constructor.
void __TBB_EXPORTED_METHOD | reset ()
| Forcefully reinitializes the context after the task tree it was associated with is completed.
bool __TBB_EXPORTED_METHOD | cancel_group_execution ()
| Initiates cancellation of all tasks in this cancellation group and its subordinate groups.
bool __TBB_EXPORTED_METHOD | is_group_execution_cancelled () const
| Returns true if the context received cancellation request.
void __TBB_EXPORTED_METHOD | register_pending_exception ()
| Records the pending exception, and cancels the task group.
void | set_priority (priority_t)
| Changes priority of the task group.
priority_t | priority () const
| Retrieves current priority of the current task group.

## Protected Member Functions

void __TBB_EXPORTED_METHOD | init ()
| Out-of-line part of the constructor.

## Friends

class | internal::generic_scheduler
class | task_scheduler_init
class | task
class | internal::allocate_root_with_context_proxy

## Detailed Description

Used to form groups of tasks.

Dummy to avoid cluttering the bulk of the header with enormous amount of ifdefs.

The context services explicit cancellation requests from user code, and unhandled exceptions intercepted during tasks execution. Intercepting an exception results in generating internal cancellation requests (which is processed in exactly the same way as external ones).

The context is associated with one or more root tasks and defines the cancellation group that includes all the descendants of the corresponding root task(s). Association is established when a context object is passed as an argument to the task::allocate_root() method. See task_group_context::task_group_context for more details.

The context can be bound to another one, and other contexts can be bound to it, forming a tree-like structure: parent -> this -> children. Arrows here designate cancellation propagation direction. If a task in a cancellation group is cancelled all the other tasks in this group and groups bound to it (as children) get cancelled too.

IMPLEMENTATION NOTE: When adding new members to task_group_context or changing types of existing ones, update the size of both padding buffers (_leading_padding and _trailing_padding) appropriately. See also VERSIONING NOTE at the constructor definition below.

## Constructor & Destructor Documentation

tbb::task_group_context::task_group_context | ( | kind_type | relation_with_parent = `bound`,
|  | uintptr_t | traits = `default_traits` |
| ) |  |  | `[inline]`

Default & binding constructor.

By default a bound context is created. That is this context will be bound (as child) to the context of the task calling task::allocate_root(this_context) method. Cancellation requests passed to the parent context are propagated to all the contexts bound to it. Similarly priority change is propagated from the parent context to its children.

If task_group_context::isolated is used as the argument, then the tasks associated with this context will never be affected by events in any other context.

Creating isolated contexts involve much less overhead, but they have limited utility. Normally when an exception occurs in an algorithm that has nested ones running, it is desirably to have all the nested algorithms cancelled as well. Such a behavior requires nested algorithms to use bound contexts.

There is one good place where using isolated algorithms is beneficial. It is a master thread. That is if a particular algorithm is invoked directly from the master thread (not from a TBB task), supplying it with explicitly created isolated context will result in a faster algorithm startup.

VERSIONING NOTE: Implementation(s) of task_group_context constructor(s) cannot be made entirely out-of-line because the run-time version must be set by the user code. This will become critically important for binary compatibility, if we ever have to change the size of the context object.

Boosting the runtime version will also be necessary if new data fields are introduced in the currently unused padding areas and these fields are updated by inline methods.

References init().

## Member Function Documentation

bool __TBB_EXPORTED_METHOD tbb::task_group_context::cancel_group_execution | ( |  | ) |

Initiates cancellation of all tasks in this cancellation group and its subordinate groups.

Returns:
  false if cancellation has already been requested, true otherwise.

Note that canceling never fails. When false is returned, it just means that another thread (or this one) has already sent cancellation request to this context or to one of its ancestors (if this context is bound). It is guaranteed that when this method is concurrently called on the same not yet cancelled context, true will be returned by one and only one invocation.

void __TBB_EXPORTED_METHOD tbb::task_group_context::init | ( |  | ) | `[protected]`

Out-of-line part of the constructor.

Singled out to ensure backward binary compatibility of the future versions.

Referenced by task_group_context().

void __TBB_EXPORTED_METHOD tbb::task_group_context::register_pending_exception | ( |  | ) |

Records the pending exception, and cancels the task group.

May be called only from inside a catch-block. If the context is already cancelled, does nothing. The method brings the task group associated with this context exactly into the state it would be in, if one of its tasks threw the currently pending exception during its execution. In other words, it emulates the actions of the scheduler's dispatch loop exception handler.

void __TBB_EXPORTED_METHOD tbb::task_group_context::reset | ( |  | ) |

Forcefully reinitializes the context after the task tree it was associated with is completed.

Because the method assumes that all the tasks that used to be associated with this context have already finished, calling it while the context is still in use somewhere in the task hierarchy leads to undefined behavior.

IMPORTANT: This method is not thread safe!

The method does not change the context's parent if it is set.

Referenced by tbb::flow::interface6::graph::wait_for_all().

The documentation for this class was generated from the following files:

- parallel_invoke.h
- task.h

Copyright © 2005-2012 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.