Name

task_scheduler_init Class — Class that represents thread’s interest in task scheduling services.

Synopsis

#include "tbb/task_soinit;

Description

A task_scheduler_init is either active or inactive. Each thread that uses a task should have one active task_scheduler_init object that stays active over the duration that the thread uses task objects. A thread may have more than one active task_scheduler_init at any given moment.

The default constructor for a task_scheduler_init activates it, and the destructor deactivates it. To defer initialization, pass the value task_scheduler_init::deferred to the constructor. Such a task_scheduler_init may be initialized later by calling the initialize method. Destruction of an initialized task_scheduler_init implicitly deactivates it. To deactivate it earlier, call the terminate method.

An optional parameter to the constructor and initialize method allows you to specify the number of threads to be used for task execution. This parameter is useful for scaling studies during development, but should not be set for production use.

To minimize time overhead, it is best to have a thread create a single task_scheduler_init object whose activation spans all uses of the library’s task scheduler. A task_scheduler_ init is not assignable or copy-constructible.

Warning

The template algorithms implicitly use the task class. Hence, creating a task_scheduler_init object is a prerequisite to using the template algorithms. The debug version of the library will report a failure to create the task_scheduler_init.

Example

	#include "tbb/task_scheduler_init"

	int main()
	    task_scheduler_init init;
	     ... use task or template algorithms here...
	    return 0;
	}
	Members
	namespace tbb {

	    class task_scheduler_init {
	    public:
	        static const int automatic = implementation-defined;
	        static const int deferred = implementation-defined;
	        task_scheduler_init( int number_of_threads=automatic );
	        ~task_scheduler_init();
	        void initialize( int number_of_threads=automatic );
	        void terminate();
	    };
	} // namespace tbb
task_scheduler_init(intnumber_of_threads=automatic)

Requirements: number_of_threads object must be one of the values in Table 9-2.

Effects: if number_of_threads==task_scheduler_init::deferred, nothing happens, and the task_scheduler_init object remains inactive. Otherwise, the task_scheduler_init object 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 are no threads with active task_scheduler_init objects yet, internal worker threads are created as described in Table 9-2. These workers sleep until the task scheduler needs them.

Table 9-2. Value for number_of_threads

number_of_threads

Semantics

task_scheduler_init::automatic

Let library determine number_of_threads based on hardware configuration.

task_scheduler_init::deferred

Defer activation actions.

Positive integer

If no worker threads exist yet, create number_of_threads-1 worker threads. If worker threads exist, do not change the number of worker threads.

~task_scheduler_init()

Effects: if the task_scheduler_init object is inactive, nothing happens. Otherwise, the task_scheduler_init object is deactivated as follows. If the thread has no other active task_scheduler_init objects, the thread deallocates the internal thread-specific resources required for scheduling task objects. If no existing thread has any active task_scheduler_init objects, the internal worker threads are terminated.

voidinitialize(intnumber_of_threads=automatic)

Requirements: the task_scheduler_init object must be inactive.

Effects: similar to the constructor.

void terminate( )

Requirements: the task_scheduler_init object must be active.

Effects: deactivates the task_scheduler_init object without destroying it. The description of the destructor specifies what deactivation entails.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.65.65