question

MN-2108 avatar image
0 Votes"
MN-2108 asked JeanineZhang-MSFT commented

Difference between the Concurrency Runtime Scheduler and Thread Pool

In the Visual Studio 2019 documentation it is stated in section "Task Scheduler (Concurrency Runtime)" that as of 2015 the concurrency::task class and related types in ppltasks.h use the Windows ThreadPool as their scheduler while algorithms like parallel_for still use the Concurrency Runtime as default scheduler. I have tried to reaseach the differences, but just can't find a clear answer. So here are my questions: What are the differences between the both scheduler in the way they work and/or how do they relate to each other? Do they have different scheduling policies and do both implement the work-stealing pattern?

c++
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JeanineZhang-MSFT avatar image
0 Votes"
JeanineZhang-MSFT answered JeanineZhang-MSFT commented

Hi,

According to your description, I wonder if you want to know what is the difference between concurrency and parallelism?If so.

Concurrency is when two or more tasks can start, run, and complete in overlapping time periods. It doesn't necessarily mean they'll ever both be running at the same instant. For example, multitasking on a single-core machine.

Parallelism is when tasks literally run at the same time, e.g. on a multi-core processor.

The Parallel Patterns Library (PPL) provides an imperative programming model that promotes scalability and ease-of-use for developing concurrent applications. The PPL builds on the scheduling and resource management components of the Concurrency Runtime.

Concurrency can occur without parallelism: for example, multitasking on a single processor system.

Parallelism is a specific form of concurrency requiring multiple processors (or a single processor capable of multiple engines of execution, such as a GPU).

With concurrency, multiple threads make forward progress, but not necessarily simultaneously.

With parallelism, threads literally execute in parallel, allowing multi-threaded programs to utilize multiple processors.

Best Regards,

Jeanine


If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for the fast answer!

I do understand the differences between concurrency and parallelism, but my first question is about the exact differences between how ppltasks (with Windows ThreadPool as scheduler) and how algorithms like parallel_for (with Concurrency Runtime default scheduler) are scheduled.

It is said that "[t]he Concurrency Runtime implements a work-stealing algorithm to extend the FIFO scheduling mechanism" of the Windows Thread pools. Does this apply to all the algorithms or is it only part of the default Concurrency Runtime scheduler used for algorithms like parallel_for?

Also an additional question for a better understanding. Do the schedulers create more threads (for waiting tasks) than there are physical processing units in case a logical thread is suspended or does the execution work in parallel until oversubscription is enabled?

0 Votes 0 ·

@MN-2108

May I know if you have got any chance to check my answer? I am glad to help if you have any other questions.

0 Votes 0 ·