#include <task.h>
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 |
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.
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.
bool __TBB_EXPORTED_METHOD tbb::task_group_context::cancel_group_execution | ( | ) |
Initiates cancellation of all tasks in this cancellation group and its subordinate groups.
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.