tbb::task_group_context Class Reference
[Task Scheduling]

Used to form groups of tasks. More...

#include <task.h>

List of all members.

Public Types

 isolated
 bound
enum  kind_type { isolated, bound }

Public Member Functions

 task_group_context (kind_type relation_with_parent=bound)
 Default & binding constructor.
void __TBB_EXPORTED_METHOD reset ()
 Forcefully reinitializes context object after an algorithm it was used with finished.
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.

Protected Member Functions

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

Friends

class task
class internal::allocate_root_with_context_proxy


Detailed Description

Used to form groups of tasks.

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 canceled all the other tasks in this group and groups bound to it (as children) get canceled too.


Constructor & Destructor Documentation

tbb::task_group_context::task_group_context ( kind_type  relation_with_parent = bound  )  [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.

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 context is involves much less overhead, but they have limited utility. Normally when an exception occur in an algorithm that has nested algorithms running one would want all the nested ones canceled as well. Such 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.


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 called on the same context, true may be returned by at most one invocation.

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

Out-of-line part of the constructor.

Separated to facilitate future support for backward binary compatibility.

void __TBB_EXPORTED_METHOD tbb::task_group_context::reset (  ) 

Forcefully reinitializes context object after an algorithm it was used with finished.

Because the method assumes that the all the tasks that used to be associated with this context have already finished, you must be extremely careful to not invalidate the context while it is still in use somewhere in the task hierarchy.

IMPORTANT: It is assumed that this method is not used concurrently!

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


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

Copyright © 2005-2009 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.