For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.
This document describes the role of scheduler policies in the Concurrency Runtime. A scheduler policy controls the strategy that the scheduler uses when it manages tasks. For example, consider an application that requires some tasks to execute at
THREAD_PRIORITY_NORMAL and other tasks to execute at
THREAD_PRIORITY_HIGHEST. You can create two scheduler instances: one that specifies the
ContextPriority policy to be
THREAD_PRIORITY_NORMAL and another that specifies the same policy to be
By using scheduler policies, you can divide the available processing resources and assign a fixed set of resources to each scheduler. For example, consider a parallel algorithm that does not scale beyond four processors. You can create a scheduler policy that limits its tasks to use no more than four processors concurrently.
The Concurrency Runtime provides a default scheduler. Therefore, you don't have to create one in your application. Because the Task Scheduler helps you fine-tune the performance of your applications, we recommend that you start with the Parallel Patterns Library (PPL) or the Asynchronous Agents Library if you are new to the Concurrency Runtime.
When you use the concurrency::CurrentScheduler::Create, concurrency::Scheduler::Create, or concurrency::Scheduler::SetDefaultSchedulerPolicy method to create a scheduler instance, you provide a concurrency::SchedulerPolicy object that contains a collection of key-value pairs that specify the behavior of the scheduler. The
SchedulerPolicy constructor takes a variable number of arguments. The first argument is the number of policy elements that you are about to specify. The remaining arguments are key-value pairs for each policy element. The following example creates a
SchedulerPolicy object that specifies three policy elements. The runtime uses default values for the policy keys that are not specified.
No code example is currently available or this language may not be supported.
The concurrency::PolicyElementKey enumeration defines the policy keys that are associated with the Task Scheduler. The following table describes the policy keys and the default value that the runtime uses for each of them.
|Policy Key||Description||Default Value|
|A concurrency::SchedulerType value that specifies the type of threads to use to schedule tasks.|
|A concurrency::SchedulingProtocolType value that specifies the scheduling algorithm to use.|
|A concurrency::DynamicProgressFeedbackType value that specifies whether to rebalance resources according to statistics-based progress information.|
Note Do not set this policy to
Each scheduler uses its own policy when it schedules tasks. The policies that are associated with one scheduler do not affect the behavior of any other scheduler. In addition, you cannot change the scheduler policy after you create the
Use only scheduler policies to control the attributes for threads that the runtime creates. Do not change the thread affinity or priority of threads that are created by the runtime because that might cause undefined behavior.
The runtime creates a default scheduler for you if you do not explicitly create one. If you want to use the default scheduler in your application, but you want to specify a policy for that scheduler to use, call the concurrency::Scheduler::SetDefaultSchedulerPolicy method before you schedule parallel work. If you do not call the
Scheduler::SetDefaultSchedulerPolicy method, the runtime uses the default policy values from the table.
Use the concurrency::CurrentScheduler::GetPolicy and the concurrency::Scheduler::GetPolicy methods to retrieve a copy of the scheduler policy. The policy values that you receive from these methods can differ from the policy values that you specify when you create the scheduler.
To examine examples that use specific scheduler policies to control the behavior of the scheduler, see How to: Specify Specific Scheduler Policies and How to: Create Agents that Use Specific Scheduler Policies.