Intel Threading Building Blocks 2.1 for Open Source

Public Types | Public Member Functions | Protected Member Functions | Friends

tbb::task_group_context Class Reference
[Task Scheduling]

Used to form groups of tasks. More...

#include <task.h>

Inheritance diagram for tbb::task_group_context:
Inheritance graph
[legend]

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 = 0 }

Public Member Functions

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

Protected Member Functions

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

Friends

class internal::allocate_root_with_context_proxy
class task

Detailed Description

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.

Definition at line 275 of file task.h.


Member Enumeration Documentation

Enumerator:
isolated 
bound 

Definition at line 290 of file task.h.

                   {
        isolated,
        bound
    };

Enumerator:
exact_exception 
concurrent_wait 
default_traits 

Definition at line 295 of file task.h.

                     {
        exact_exception = 0x0001ul << traits_offset,
        concurrent_wait = 0x0004ul << traits_offset,
#if TBB_USE_CAPTURED_EXCEPTION
        default_traits = 0
#else
        default_traits = exact_exception
#endif /* !TBB_USE_CAPTURED_EXCEPTION */
    };


Constructor & Destructor Documentation

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

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.

Definition at line 382 of file task.h.

References init().

        : my_kind(relation_with_parent)
        , my_version_and_traits(1 | traits)
    {
        init();
    }

tbb::task_group_context::~task_group_context (  ) 

Member Function Documentation

bool tbb::task_group_context::cancel_group_execution (  ) 
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.

Referenced by tbb::internal::task_group_base::cancel().

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

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

Referenced by task_group_context().

bool tbb::task_group_context::is_group_execution_cancelled (  )  const
void tbb::task_group_context::register_pending_exception (  ) 

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.

Referenced by tbb::internal::task_group_base::internal_run_and_wait().

void tbb::task_group_context::reset (  ) 

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::internal::task_group_base::wait().


Friends And Related Function Documentation

friend class internal::allocate_root_with_context_proxy [friend]

Definition at line 431 of file task.h.

friend class task [friend]

Definition at line 430 of file task.h.


Member Data Documentation

Definition at line 309 of file task.h.

Definition at line 308 of file task.h.


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

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

Licensed under the GNU General Public License 2 with the runtime exception.

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.