Chapter 23. Parallel Programming
In this chapter, we cover the multithreading APIs and constructs aimed at leveraging multicore processors:
Parallel LINQ or PLINQ
The
ParallelclassThe task parallelism constructs
The concurrent collections
These constructs are collectively known (loosely) as Parallel Framework (PFX). The Parallel class together with the task parallelism constructs is called the Task Parallel Library (TPL).
You’ll need to be comfortable with the fundamentals in Chapter 14 before reading this chapter—particularly locking, thread safety, and the Task class.
Note
.NET Core offers a number of additional specialized APIs to help with parallel and asynchronous programming:
System.Threading.Channels.Channelis a high-performance asynchronous producer/consumer queue, new to .NET Core 3.Microsoft Dataflow (in the
System.Threading.Tasks.Dataflownamespace) is a sophisticated API for creating networks of buffered blocks that execute actions or data transformations in parallel, with a semblance to actor/agent programming.Reactive Extensions implements LINQ over
IObservable(an alternative abstraction toIAsyncEnumerable) and excels at combining asynchronous streams. Reactive extensions ships in the System.Reactive NuGet package.
Why PFX?
Over the past 15 years, CPU manufacturers have shifted from single-core to multicore processors. This is problematic for us as programmers because single-threaded code does not automatically run faster as a result of those extra ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access