task_scheduler_init max_threads


This feature is deprecated and will be removed in the future.


The value max_threads shall be one of the values in the table below.


If max_threads==task_scheduler_init::deferred, nothing happens, and the task_scheduler_init remains inactive. Otherwise, the task_scheduler_init is activated as follows. If the thread has no other active task_scheduler_init objects, the thread allocates internal thread-specific resources required for scheduling task objects. If there were no threads with active task_scheduler_init objects yet, then internal worker threads are created as described in the table below. These workers sleep until needed by the task scheduler. Each worker created by the scheduler has an implicit active task_scheduler_init object.


As of Intel® Threading Building Blocks (Intel® TBB) 3.0, it is meaningful for the parameter max_threads to differ for different calling threads. For example, if thread A specifies max_threads=3 and thread B specifies max_threads=7, then A is limited to having 2 workers, but B can have up to 6 workers. Since workers may be shared between A and B, the total number of worker threads created by the scheduler could be 6.


Some implementations create more workers than necessary. However, the excess workers remain asleep unless needed.

The optional parameter thread_stack_size specifies the stack size of each worker thread. A value of 0 specifies use of a default stack size. The first active task_scheduler_init establishes the stack size for all worker threads.

Values for max_threads




Let library determine max_threads based on hardware configuration.


Defer activation actions.

positive integer

Request that up to max_threads-1 worker threads work on behalf of the calling thread at any one time.

For more complete information about compiler optimizations, see our Optimization Notice.