tbb::interface7::task_arena Class Reference

`#include <task_arena.h>`

Inheritance diagram for tbb::interface7::task_arena:
Collaboration diagram for tbb::interface7::task_arena:

## Classes

struct | attach
| Tag class used to indicate the "attaching" constructor. More...

## Public Member Functions

| task_arena (int max_concurrency_=automatic, unsigned reserved_for_masters=1)
| Creates task_arena with certain concurrency limits. More...
| task_arena (const task_arena &s)
| Copies settings from another task_arena. More...
| task_arena (attach)
| Creates an instance of task_arena attached to the current arena of the thread. More...
void | initialize ()
| Forces allocation of the resources for the task_arena as specified in constructor arguments. More...
void | initialize (int max_concurrency_, unsigned reserved_for_masters=1)
| Overrides concurrency level and forces initialization of internal representation. More...
void | initialize (attach)
| Attaches this instance to the current arena of the thread. More...
void | terminate ()
| ~task_arena ()
bool | is_active () const
template<typename F >
void | enqueue (F &&f)
template<typename F >
__TBB_DEPRECATED void | enqueue (F &&f, priority_t p)
template<typename F >
internal::return_type_or_void< F >::type | execute (F &f)
template<typename F >
internal::return_type_or_void< F >::type | execute (const F &f)
int | max_concurrency () const
| Returns the maximal number of threads that can work inside the arena. More...

## Static Public Member Functions

static int | current_thread_index ()

## Private Member Functions

void | mark_initialized ()
template<typename F >
void | enqueue_impl (__TBB_FORWARDING_REF(F) f, priority_t p=priority_t(0))
template<typename R , typename F >
R | execute_impl (F &f)

## Friends

class | tbb::internal::task_scheduler_observer_v3
void | task::enqueue (task &, task_arena &, priority_t)
int | tbb::this_task_arena::max_concurrency ()

## Additional Inherited Members

Static Public Attributes inherited from tbb::interface7::internal::task_arena_base
static const int | automatic = -1
| Typedef for number of threads that is automatic. More...
static const int | not_initialized = -2
Protected Types inherited from tbb::interface7::internal::task_arena_base
enum | { default_flags, exact_exception_flag = task_group_context::exact_exception }
Protected Member Functions inherited from tbb::interface7::internal::task_arena_base
| task_arena_base (int max_concurrency, unsigned reserved_for_masters)
void __TBB_EXPORTED_METHOD | internal_initialize ()
void __TBB_EXPORTED_METHOD | internal_terminate ()
void __TBB_EXPORTED_METHOD | internal_attach ()
void __TBB_EXPORTED_METHOD | internal_enqueue (task &, intptr_t) const
void __TBB_EXPORTED_METHOD | internal_execute (delegate_base &) const
void __TBB_EXPORTED_METHOD | internal_wait () const
Static Protected Member Functions inherited from tbb::interface7::internal::task_arena_base
static int __TBB_EXPORTED_FUNC | internal_current_slot ()
static int __TBB_EXPORTED_FUNC | internal_max_concurrency (const task_arena *)
Protected Attributes inherited from tbb::interface7::internal::task_arena_base
internal::arena * | my_arena
| NULL if not currently initialized. More...
task_group_context * | my_context
| default context of the arena More...
int | my_max_concurrency
| Concurrency level for deferred initialization. More...
unsigned | my_master_slots
| Reserved master slots. More...
intptr_t | my_version_and_traits
| Special settings. More...
bool | my_initialized

## Detailed Description

1-to-1 proxy representation class of scheduler's arena Constructors set up settings only, real construction is deferred till the first method invocation Destructor only removes one of the references to the inner arena representation. Final destruction happens when all the references (and the work) are gone.

Definition at line 228 of file task_arena.h.

## Constructor & Destructor Documentation

## task_arena() [1/3]

tbb::interface7::task_arena::task_arena | ( | int | max_concurrency_ = `automatic`,
|  | unsigned | reserved_for_masters = `1`
| ) |  |

inline

Creates task_arena with certain concurrency limits.

Sets up settings only, real construction is deferred till the first method invocation

- max_concurrency specifies total number of slots in arena where threads work
- reserved_for_masters specifies number of slots to be used by master threads only. Value of 1 is default and reflects behavior of implicit arenas.

Definition at line 282 of file task_arena.h.

: task_arena_base(max_concurrency_, reserved_for_masters)
{}

## task_arena() [2/3]

tbb::interface7::task_arena::task_arena | ( | const task_arena & | s | ) |

inline

Copies settings from another task_arena.

Definition at line 298 of file task_arena.h.

: task_arena_base(s.my_max_concurrency, s.my_master_slots)
{}

## task_arena() [3/3]

tbb::interface7::task_arena::task_arena | ( | attach |  | ) |

inline explicit

Creates an instance of task_arena attached to the current arena of the thread.

Definition at line 307 of file task_arena.h.

: task_arena_base(automatic, 1) // use default settings if attach fails
{
internal_attach();
if( my_arena ) my_initialized = true;
}

## ~task_arena()

tbb::interface7::task_arena::~task_arena | ( |  | ) |

inline

Removes the reference to the internal arena representation, and destroys the external object. Not thread safe wrt concurrent invocations of other methods.

Definition at line 368 of file task_arena.h.

{
terminate();
}

## Member Function Documentation

## current_thread_index()

static int tbb::interface7::task_arena::current_thread_index | ( |  | ) |

inline static

Returns the index, aka slot number, of the calling thread in its current arena This method is deprecated and replaced with this_task_arena::current_thread_index()

Definition at line 448 of file task_arena.h.

{
return internal_current_slot();
}

Referenced by tbb::this_task_arena::current_thread_index().

Here is the caller graph for this function:

## enqueue() [1/2]

template<typename F >

void tbb::interface7::task_arena::enqueue | ( | F && | f | ) |

inline

Enqueues a task into the arena to process a functor, and immediately returns. Does not require the calling thread to join the arena

Definition at line 381 of file task_arena.h.

{
enqueue_impl(std::forward<F>(f));
}

## enqueue() [2/2]

template<typename F >

__TBB_DEPRECATED void tbb::interface7::task_arena::enqueue | ( | F && | f,
|  | priority_t | p
| ) |  |

inline

Enqueues a task with priority p into the arena to process a functor f, and immediately returns. Does not require the calling thread to join the arena

Definition at line 396 of file task_arena.h.

{
#if __TBB_PREVIEW_CRITICAL_TASKS
__TBB_ASSERT(p == priority_low || p == priority_normal || p == priority_high
|| p == internal::priority_critical, "Invalid priority level value");
#else
__TBB_ASSERT(p == priority_low || p == priority_normal || p == priority_high, "Invalid priority level value");
#endif
enqueue_impl(std::forward<F>(f), p);
}

References __TBB_ASSERT, p, tbb::internal::priority_critical, tbb::priority_high, tbb::priority_low, and tbb::priority_normal.

## enqueue_impl()

template<typename F >

void tbb::interface7::task_arena::enqueue_impl | ( | __TBB_FORWARDING_REF(F) | f,
|  | priority_t | p = `priority_t(0)`
| ) |  |

inline private

Definition at line 251 of file task_arena.h.

{
#if !__TBB_TASK_PRIORITY
intptr_t p = 0;
#endif
initialize();
#if __TBB_TASK_GROUP_CONTEXT
internal_enqueue(*new(task::allocate_root(*my_context)) internal::function_task< typename internal::strip<F>::type >(internal::forward<F>(f)), p);
#else
internal_enqueue(*new(task::allocate_root()) internal::function_task< typename internal::strip<F>::type >(internal::forward<F>(f)), p);
#endif /* __TBB_TASK_GROUP_CONTEXT */
}

References tbb::task::allocate_root(), and p.

Here is the call graph for this function:

## execute() [1/2]

template<typename F >

internal::return_type_or_void<F>::type tbb::interface7::task_arena::execute | ( | const F & | f | ) |

inline

Joins the arena and executes a constant functor, then returns If not possible to join, wraps the functor into a task, enqueues it and waits for task completion Can decrement the arena demand for workers, causing a worker to leave and free a slot to the calling thread Since C++11, the method returns the value returned by functor (prior to C++11 it returns void).

Definition at line 432 of file task_arena.h.

{
return execute_impl<typename internal::return_type_or_void<F>::type>(f);
}

References type.

## execute() [2/2]

template<typename F >

internal::return_type_or_void<F>::type tbb::interface7::task_arena::execute | ( | F & | f | ) |

inline

Joins the arena and executes a mutable functor, then returns If not possible to join, wraps the functor into a task, enqueues it and waits for task completion Can decrement the arena demand for workers, causing a worker to leave and free a slot to the calling thread Since C++11, the method returns the value returned by functor (prior to C++11 it returns void).

Definition at line 423 of file task_arena.h.

{
return execute_impl<typename internal::return_type_or_void<F>::type>(f);
}

References type.

Referenced by tbb::flow::interface10::graph::run(), tbb::flow::interface11::internal::spawn_in_graph_arena(), and tbb::flow::interface10::graph::wait_for_all().

Here is the caller graph for this function:

## execute_impl()

template<typename R , typename F >

R tbb::interface7::task_arena::execute_impl | ( | F & | f | ) |

inline private

Definition at line 268 of file task_arena.h.

{
initialize();
internal::delegated_function<F, R> d(f);
internal_execute(d);
return d.consume_result();
}

References d.

## initialize() [1/3]

void tbb::interface7::task_arena::initialize | ( |  | ) |

inline

Forces allocation of the resources for the task_arena as specified in constructor arguments.

Definition at line 315 of file task_arena.h.

{
if( !my_initialized ) {
internal_initialize();
mark_initialized();
}
}

Referenced by tbb::flow::interface10::graph::prepare_task_arena().

Here is the caller graph for this function:

## initialize() [2/3]

void tbb::interface7::task_arena::initialize | ( | attach |  | ) |

inline

Attaches this instance to the current arena of the thread.

Definition at line 347 of file task_arena.h.

{
// TODO: decide if this call must be thread-safe
__TBB_ASSERT(!my_arena, "Impossible to modify settings of an already initialized task_arena");
if( !my_initialized ) {
internal_attach();
if ( !my_arena ) internal_initialize();
mark_initialized();
}
}

References __TBB_ASSERT.

## initialize() [3/3]

void tbb::interface7::task_arena::initialize | ( | int | max_concurrency_,
|  | unsigned | reserved_for_masters = `1`
| ) |  |

inline

Overrides concurrency level and forces initialization of internal representation.

Definition at line 323 of file task_arena.h.

{
// TODO: decide if this call must be thread-safe
__TBB_ASSERT(!my_arena, "Impossible to modify settings of an already initialized task_arena");
if( !my_initialized ) {
my_max_concurrency = max_concurrency_;
my_master_slots = reserved_for_masters;
initialize();
}
}

References __TBB_ASSERT.

## is_active()

bool tbb::interface7::task_arena::is_active | ( |  | ) | const

inline

Returns true if the arena is active (initialized); false otherwise. The name was chosen to match a task_scheduler_init method with the same semantics.

Definition at line 374 of file task_arena.h.

{ return my_initialized; }

Referenced by tbb::flow::interface11::internal::enqueue_in_graph_arena(), tbb::flow::interface10::graph::prepare_task_arena(), and tbb::flow::interface11::internal::spawn_in_graph_arena().

Here is the caller graph for this function:

## mark_initialized()

void tbb::interface7::task_arena::mark_initialized | ( |  | ) |

inline private

Definition at line 236 of file task_arena.h.

{
__TBB_ASSERT( my_arena, "task_arena initialization is incomplete" );
#if __TBB_TASK_GROUP_CONTEXT
__TBB_ASSERT( my_context, "task_arena initialization is incomplete" );
#endif
#if TBB_USE_THREADING_TOOLS
// Actual synchronization happens in internal_initialize & internal_attach.
// The race on setting my_initialized is benign, but should be hidden from Intel(R) Inspector
internal::as_atomic(my_initialized).fetch_and_store<release>(true);
#else
my_initialized = true;
#endif
}

References __TBB_ASSERT, tbb::internal::as_atomic(), and tbb::release.

Here is the call graph for this function:

## max_concurrency()

int tbb::interface7::task_arena::max_concurrency | ( |  | ) | const

inline

Returns the maximal number of threads that can work inside the arena.

Definition at line 453 of file task_arena.h.

{
// Handle special cases inside the library
return (my_max_concurrency>1) ? my_max_concurrency : internal_max_concurrency(this);
}

## terminate()

void tbb::interface7::task_arena::terminate | ( |  | ) |

inline

Removes the reference to the internal arena representation. Not thread safe wrt concurrent invocations of other methods.

Definition at line 359 of file task_arena.h.

{
if( my_initialized ) {
internal_terminate();
my_initialized = false;
}
}

Referenced by tbb::flow::interface10::graph::prepare_task_arena().

Here is the caller graph for this function:

## Friends And Related Function Documentation

## task::enqueue

void task::enqueue | ( | task & | ,
|  | task_arena & | ,
|  | priority_t |
| ) |  |

friend

## tbb::internal::task_scheduler_observer_v3

friend class tbb::internal::task_scheduler_observer_v3

friend

Definition at line 229 of file task_arena.h.

## tbb::this_task_arena::max_concurrency

int tbb::this_task_arena::max_concurrency | ( |  | ) |

friend

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

- task_arena.h

tbb::interface7::internal::task_arena_base::internal_initialize
void __TBB_EXPORTED_METHOD internal_initialize()
tbb::interface7::internal::task_arena_base::internal_terminate
void __TBB_EXPORTED_METHOD internal_terminate()
tbb::interface7::internal::task_arena_base::automatic
static const int automatic
Typedef for number of threads that is automatic.
Definition: task_arena.h:205
tbb::interface7::internal::task_arena_base::my_context
task_group_context * my_context
default context of the arena
Definition: task_arena.h:124
tbb::interface7::internal::task_arena_base::my_max_concurrency
int my_max_concurrency
Concurrency level for deferred initialization.
Definition: task_arena.h:128
tbb::interface7::internal::task_arena_base::internal_max_concurrency
static int __TBB_EXPORTED_FUNC internal_max_concurrency(const task_arena *)
__TBB_ASSERT
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
tbb::interface7::task_arena::initialize
void initialize()
Forces allocation of the resources for the task_arena as specified in constructor arguments.
Definition: task_arena.h:315
tbb::interface7::internal::task_arena_base::my_arena
internal::arena * my_arena
NULL if not currently initialized.
Definition: task_arena.h:120
tbb::interface7::task_arena::terminate
void terminate()
Definition: task_arena.h:359
tbb::internal::priority_critical
static const int priority_critical
Definition: task.h:302
tbb::priority_normal
Definition: task.h:307
tbb::interface7::internal::task_arena_base::my_initialized
bool my_initialized
Definition: task_arena.h:136
tbb::interface7::internal::task_arena_base::internal_enqueue
void __TBB_EXPORTED_METHOD internal_enqueue(task &, intptr_t) const
d
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d
Definition: ittnotify_static.h:109
tbb::interface7::internal::task_arena_base::internal_attach
void __TBB_EXPORTED_METHOD internal_attach()
tbb::interface7::internal::task_arena_base::internal_current_slot
static int __TBB_EXPORTED_FUNC internal_current_slot()
tbb::interface7::task_arena::mark_initialized
void mark_initialized()
Definition: task_arena.h:236
tbb::interface7::internal::task_arena_base::task_arena_base
task_arena_base(int max_concurrency, unsigned reserved_for_masters)
Definition: task_arena.h:163
tbb::internal::strip::type
T type
Definition: _template_helpers.h:38
tbb::interface7::internal::task_arena_base::internal_execute
void __TBB_EXPORTED_METHOD internal_execute(delegate_base &) const
tbb::interface7::internal::task_arena_base::my_master_slots
unsigned my_master_slots
Reserved master slots.
Definition: task_arena.h:131
tbb::priority_low
Definition: task.h:308
s
void const char const char int ITT_FORMAT __itt_group_sync s
Definition: ittnotify_static.h:91
tbb::task::allocate_root
static internal::allocate_root_proxy allocate_root()
Returns proxy for overloaded new that allocates a root task.
Definition: task.h:652
tbb::internal::as_atomic
atomic< T > & as_atomic(T &t)
Definition: atomic.h:572
tbb::priority_high
Definition: task.h:309
tbb::interface7::task_arena::enqueue_impl
void enqueue_impl(__TBB_FORWARDING_REF(F) f, priority_t p=priority_t(0))
Definition: task_arena.h:251
p
void const char const char int ITT_FORMAT __itt_group_sync p
Definition: ittnotify_static.h:91
tbb::release
Release.
Definition: atomic.h:59
type
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type type
Definition: ittnotify_static.h:198

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