Intel(R) Threading Building Blocks Doxygen Documentation
version 4.2.3
|
Used to form groups of tasks. More...
#include <task.h>
Public Types | |
enum | kind_type { isolated, bound } |
enum | traits_type { exact_exception = 0x0001ul << traits_offset, fp_settings = 0x0002ul << traits_offset, concurrent_wait = 0x0004ul << traits_offset, default_traits = exact_exception } |
Public Member Functions | |
task_group_context (kind_type relation_with_parent=bound, uintptr_t t=default_traits) | |
Default & binding constructor. More... | |
task_group_context (internal::string_index name) | |
__TBB_EXPORTED_METHOD | ~task_group_context () |
void __TBB_EXPORTED_METHOD | reset () |
Forcefully reinitializes the context after the task tree it was associated with is completed. More... | |
bool __TBB_EXPORTED_METHOD | cancel_group_execution () |
Initiates cancellation of all tasks in this cancellation group and its subordinate groups. More... | |
bool __TBB_EXPORTED_METHOD | is_group_execution_cancelled () const |
Returns true if the context received cancellation request. More... | |
void __TBB_EXPORTED_METHOD | register_pending_exception () |
Records the pending exception, and cancels the task group. More... | |
void __TBB_EXPORTED_METHOD | capture_fp_settings () |
Captures the current FPU control settings to the context. More... | |
__TBB_DEPRECATED_IN_VERBOSE_MODE void | set_priority (priority_t) |
Changes priority of the task group. More... | |
__TBB_DEPRECATED_IN_VERBOSE_MODE priority_t | priority () const |
Retrieves current priority of the current task group. More... | |
uintptr_t | traits () const |
Returns the context's trait. More... | |
Protected Member Functions | |
void __TBB_EXPORTED_METHOD | init () |
Out-of-line part of the constructor. More... | |
Private Types | |
enum | version_traits_word_layout { traits_offset = 16, version_mask = 0xFFFF, traits_mask = 0xFFFFul << traits_offset } |
enum | state { may_have_children = 1, next_state_value, low_unused_state_bit = (next_state_value-1)*2 } |
typedef internal::tbb_exception_ptr | exception_container_type |
Private Member Functions | |
template<typename T > | |
void | propagate_task_group_state (T task_group_context::*mptr_state, task_group_context &src, T new_state) |
Propagates any state change detected to *this, and as an optimisation possibly also upward along the heritage line. More... | |
void | bind_to (internal::generic_scheduler *local_sched) |
Registers this context with the local scheduler and binds it to its parent context. More... | |
void | register_with (internal::generic_scheduler *local_sched) |
Registers this context with the local scheduler. More... | |
void | copy_fp_settings (const task_group_context &src) |
Copies FPU control setting from another context. More... | |
![]() | |
no_copy (const no_copy &)=delete | |
no_copy ()=default | |
Private Attributes | |
union { | |
__TBB_atomic kind_type my_kind | |
Flavor of this context: bound or isolated. More... | |
uintptr_t _my_kind_aligner | |
}; | |
task_group_context * | my_parent |
Pointer to the context of the parent cancellation group. NULL for isolated contexts. More... | |
internal::context_list_node_t | my_node |
Used to form the thread specific list of contexts without additional memory allocation. More... | |
__itt_caller | itt_caller |
Used to set and maintain stack stitching point for Intel Performance Tools. More... | |
char | _leading_padding [internal::NFS_MaxLineSize - 2 *sizeof(uintptr_t) - sizeof(void *) - sizeof(internal::context_list_node_t) - sizeof(__itt_caller) - sizeof(internal::cpu_ctl_env_space)] |
Leading padding protecting accesses to frequently used members from false sharing. More... | |
internal::cpu_ctl_env_space | my_cpu_ctl_env |
Space for platform-specific FPU settings. More... | |
uintptr_t | my_cancellation_requested |
Specifies whether cancellation was requested for this task group. More... | |
uintptr_t | my_version_and_traits |
Version for run-time checks and behavioral traits of the context. More... | |
exception_container_type * | my_exception |
Pointer to the container storing exception being propagated across this task group. More... | |
internal::generic_scheduler * | my_owner |
Scheduler instance that registered this context in its thread specific list. More... | |
uintptr_t | my_state |
Internal state (combination of state flags, currently only may_have_children). More... | |
intptr_t | my_priority |
Priority level of the task group (in normalized representation) More... | |
internal::string_index | my_name |
Description of algorithm for scheduler based instrumentation. More... | |
char | _trailing_padding [internal::NFS_MaxLineSize - 2 *sizeof(uintptr_t) - 2 *sizeof(void *) - sizeof(intptr_t) - sizeof(internal::string_index)] |
Trailing padding protecting accesses to frequently used members from false sharing. More... | |
Static Private Attributes | |
static const kind_type | binding_required = bound |
static const kind_type | binding_completed = kind_type(bound+1) |
static const kind_type | detached = kind_type(binding_completed+1) |
static const kind_type | dying = kind_type(detached+1) |
Friends | |
class | internal::generic_scheduler |
class | task_scheduler_init |
class | task_arena |
class | task |
class | internal::allocate_root_with_context_proxy |
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 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.
Enumerator | |
---|---|
isolated | |
bound |
Definition at line 377 of file task.h.
|
private |
Enumerator | |
---|---|
exact_exception | |
fp_settings | |
concurrent_wait | |
default_traits |
Definition at line 382 of file task.h.
|
private |
Enumerator | |
---|---|
traits_offset | |
version_mask | |
traits_mask |
|
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.
Definition at line 504 of file task.h.
References init().
|
inline |
Definition at line 514 of file task.h.
References init().
__TBB_EXPORTED_METHOD tbb::task_group_context::~task_group_context | ( | ) |
|
private |
Registers this context with the local scheduler and binds it to its parent context.
bool __TBB_EXPORTED_METHOD tbb::task_group_context::cancel_group_execution | ( | ) |
Initiates cancellation of all tasks in this cancellation group and its subordinate groups.
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_EXPORTED_METHOD tbb::task_group_context::capture_fp_settings | ( | ) |
Captures the current FPU control settings to the context.
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 FPU control settings of the context's parent.
|
private |
Copies FPU control setting from another context.
|
protected |
Out-of-line part of the constructor.
Singled out to ensure backward binary compatibility of the future versions.
Referenced by task_group_context().
bool __TBB_EXPORTED_METHOD tbb::task_group_context::is_group_execution_cancelled | ( | ) | const |
Returns true if the context received cancellation request.
Referenced by tbb::internal::task_group_base::internal_run_and_wait(), tbb::internal::task_group_base::is_canceling(), tbb::interface9::internal::parallel_quick_sort(), tbb::internal::task_group_base::wait(), and tbb::flow::interface10::graph::wait_for_all().
__TBB_DEPRECATED_IN_VERBOSE_MODE priority_t tbb::task_group_context::priority | ( | ) | const |
Retrieves current priority of the current task group.
|
private |
Propagates any state change detected to *this, and as an optimisation possibly also upward along the heritage line.
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.
Referenced by tbb::internal::task_group_base::internal_run_and_wait().
|
private |
Registers this context with the local scheduler.
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::internal::task_group_base::wait(), and tbb::flow::interface10::graph::wait_for_all().
__TBB_DEPRECATED_IN_VERBOSE_MODE void tbb::task_group_context::set_priority | ( | priority_t | ) |
Changes priority of the task group.
|
inline |
Returns the context's trait.
Definition at line 578 of file task.h.
References my_version_and_traits, and traits_mask.
Referenced by tbb::flow::interface10::graph::wait_for_all().
|
friend |
|
friend |
|
friend |
|
friend |
union { ... } |
|
private |
Leading padding protecting accesses to frequently used members from false sharing.
Read accesses to the field my_cancellation_requested are on the hot path inside the scheduler. This padding ensures that this field never shares the same cache line with a local variable that is frequently written to.
|
private |
Trailing padding protecting accesses to frequently used members from false sharing.
|
staticprivate |
|
private |
Used to set and maintain stack stitching point for Intel Performance Tools.
Definition at line 418 of file task.h.
Referenced by tbb::internal::custom_scheduler< SchedulerTraits >::process_bypass_loop().
|
private |
Specifies whether cancellation was requested for this task group.
Definition at line 440 of file task.h.
Referenced by tbb::internal::custom_scheduler< SchedulerTraits >::process_bypass_loop().
|
private |
|
private |
__TBB_atomic kind_type tbb::task_group_context::my_kind |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
Version for run-time checks and behavioral traits of the context.
Version occupies low 16 bits, and traits (zero or more ORed enumerators from the traits_type enumerations) take the next 16 bits. Original (zeroth) version of the context did not support any traits.
Definition at line 446 of file task.h.
Referenced by traits().