Chapter 22. 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
SpinLockandSpinWait
These are new to Framework 4.0 and are collectively known (loosely)
as PFX (Parallel Framework). The Parallel class together with the task
parallelism constructs is called the Task Parallel
Library or TPL.
Framework 4.0 also adds a number of lower-level threading constructs that are aimed equally at traditional multithreading. We covered these in the previous chapter:
The low-latency signaling constructs:
SemaphoreSlim(see the section Locking)ManualResetEventSlim(see the section Signaling with Event Wait Handles)CountdownEvent(see the section Signaling with Event Wait Handles)Barrier(see the section The Barrier Class)
Cancellation tokens for cooperative cancellation (see the section Safe Cancellation)
The lazy initialization classes (see the section Lazy Initialization)
ThreadLocal<T>(see the section Thread-Local Storage)
You’ll need to be comfortable with the fundamentals in Chapter 21 before reading this chapter—particularly locking and thread safety.
Why PFX?
In recent times, CPU clock speeds have stagnated and manufacturers have shifted their focus to increasing core counts. This is problematic for us as programmers because our standard single-threaded code will not automatically run faster as a result of those extra cores.
Leveraging ...
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