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
 exact_exception = 0x0001ul << traits_offset
 no_cancellation = 0x0002ul << traits_offset
 concurrent_wait = 0x0004ul << traits_offset
 default_traits
enum  kind_type { isolated, bound }
enum  traits_type { exact_exception = 0x0001ul << traits_offset, no_cancellation = 0x0002ul << 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.

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.

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.

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 canceled 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 whenever new fields are introduced in the currently unused padding areas or the meaning of the existing fields is changed or extended.


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.

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 canceled, 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.


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.