Intel® oneAPI Threading Building Blocks Developer Guide and API Reference
global_control
[scheduler.global_control]
Use this class to control certain settings or behavior of the oneTBB dynamic library.
An object of class global_control, or a “control variable”, affects one of several behavioral aspects, or parameters, of TBB. The global_control class is primarily intended for use at the application level, to control the whole application behavior.
The current set of parameters that you can modify is defined by the global_control::parameter enumeration. The parameter and the value it should take are specified as arguments to the constructor of a control variable. The impact of the control variable ends when its lifetime is complete.
Control variables can be created in different threads, and may have nested or overlapping scopes. However, at any point in time each controlled parameter has a single active value that applies to the whole process. This value is selected from all currently existing control variables by applying a parameter-specific selection rule.
// Defined in header <oneapi/tbb/global_control.h>
namespace oneapi {
namespace tbb {
class global_control {
public:
enum parameter {
max_allowed_parallelism,
thread_stack_size,
terminate_on_exception,
leave_policy
};
global_control(parameter p, size_t value);
// Available only when T is an enumeration type
template <typename T>
global_control(parameter p, T value);
~global_control();
static size_t active_value(parameter param);
};
} // namespace tbb
} // namespace oneapi
Member types and constants
enumparameter::max_allowed_parallelism
Selection rule: minimum
Limits total number of worker threads that can be active in the task scheduler to parameter_value - 1.
enumparameter::thread_stack_size
Selection rule: maximum
Set stack size for working threads created by the library.
enumparameter::terminate_on_exception
Selection rule: logical disjunction
Setting the parameter to 1 causes termination in any condition that would throw or rethrow an exception. If set to 0 (default), the parameter does not affect the implementation behavior.
enumparameter::leave_policy
Selection rule: the first active request for task_arena::leave_policy::fast determines the active value and stays in effect until the corresponding object is destroyed. The effect of other leave_policy requests made while it is active is unspecified.
Sets the application-wide default for how quickly worker threads leave an arena when there is no more work available. The value must be one of the task_arena::leave_policy enumerators.
See Worker Thread Retention for the description of leave policies and how this parameter interacts with the per-arena task_arena::leave_policy setting.
Member functions
global_control(parameterparam, size_tvalue)
Constructs a global_control object with a specified control parameter and its value.
template<typenameT>global_control(parameterparam, Tvalue)
Constructs a global_control object with a specified control parameter and its value given as an enumerator. Participates in overload resolution only if T is an enumeration type. The behavior is equivalent to global_control(param, static_cast<size_t>(value)).
Currently, this constructor is intended for the leave_policy parameter, which accepts task_arena::leave_policy enumerators.
~global_control()
Destructs a control variable object and ends it’s impact.
staticsize_tactive_value(parameterparam)
Returns the currently active value of the setting defined by param.
See also: