# tbb::task_scheduler_init Class Reference
[Task Scheduling]

Class delimiting the scope of task scheduler activity. More...

`#include <task_scheduler_init.h>`

List of all members.

## Public Member Functions

void __TBB_EXPORTED_METHOD | initialize (int number_of_threads=automatic)
| Ensure that scheduler exists for this thread.
void __TBB_EXPORTED_METHOD | initialize (int number_of_threads, stack_size_type thread_stack_size)
| The overloaded method with stack size parameter.
void __TBB_EXPORTED_METHOD | terminate ()
| Inverse of method initialize.
| task_scheduler_init (int number_of_threads=automatic, stack_size_type thread_stack_size=0, bool wait_workers_in_terminate=false) task_scheduler_init(int number_of_threads
| Shorthand for default constructor followed by call to initialize(number_of_threads).
bool | is_active () const
| Returns true if scheduler is active (initialized); false otherwise.

## Public Attributes

stack_size_type | thread_stack_size

## Static Public Attributes

static const int | automatic = -1
| Typedef for number of threads that is automatic.
static const int | deferred = -2
| Argument to initialize() or constructor that causes initialization to be deferred.

## Detailed Description

Class delimiting the scope of task scheduler activity.

A thread can construct a task_scheduler_init object and keep it alive while it uses TBB's tasking subsystem (including parallel algorithms).

This class allows to customize properties of the TBB task pool to some extent. For example it can limit concurrency level of parallel work initiated by the given thread. It also can be used to specify stack size of the TBB worker threads, though this setting is not effective if the thread pool has already been created.

If a parallel construct is used without task_scheduler_init object previously created, the scheduler will be initialized automatically with default settings, and will persist until this thread exits. Default concurrency level is defined as described in task_scheduler_init::initialize().

## Member Function Documentation

void __TBB_EXPORTED_METHOD tbb::task_scheduler_init::initialize | ( | int | number_of_threads,
|  | stack_size_type | thread_stack_size |
| ) |  |  |

The overloaded method with stack size parameter.

Overloading is necessary to preserve ABI compatibility

void __TBB_EXPORTED_METHOD tbb::task_scheduler_init::initialize | ( | int | number_of_threads = `automatic` | ) |

Ensure that scheduler exists for this thread.

A value of -1 lets TBB decide on the number of threads, which is usually maximal hardware concurrency for this process, that is the number of logical CPUs on the machine (possibly limited by the processor affinity mask of this process (Windows) or of this thread (Linux, FreeBSD). It is preferable option for production code because it helps to avoid nasty surprises when several TBB based components run side-by-side or in a nested fashion inside the same process.

The number_of_threads is ignored if any other task_scheduler_inits currently exist. A thread may construct multiple task_scheduler_inits. Doing so does no harm because the underlying scheduler is reference counted.

## Member Data Documentation

stack_size_type tbb::task_scheduler_init::thread_stack_size

Initial value:

    0 )
    #endif
      : my_scheduler(NULL)  {

            __TBB_ASSERT( !(thread_stack_size & propagation_mode_mask), "Requested stack size is not aligned" );
    #if TBB_USE_EXCEPTIONS
            thread_stack_size |= TBB_USE_CAPTURED_EXCEPTION ? propagation_mode_captured : propagation_mode_exact;
    #endif
    #if __TBB_SUPPORTS_WORKERS_WAITING_IN_TERMINATE
            if (wait_workers_in_terminate)
                my_scheduler = (internal::scheduler*)wait_workers_in_terminate_flag;
    #endif
            initialize( number_of_threads, thread_stack_size );
        }

        ~task_scheduler_init() {
            if( my_scheduler )
                terminate();
            internal::poison_pointer( my_scheduler );
        }

        static int __TBB_EXPORTED_FUNC default_num_threads ()

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

- task_scheduler_init.h

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