Chapter 22 Parallel Programming
What’s in This Chapter
- Advantages of multithreading
- PLINQ,
BackgroundWorker
, TPL, tasks, and threads - Interacting with the UI thread
- Race conditions and deadlock
- Thread-safe classes and collections
Wrox.com Downloads for This Chapter
Please note that all the code examples for this chapter are available as a part of this chapter’s code download on the book’s website at www.wrox.com/go/csharp5programmersref on the Download Code tab.
One way to improve a program’s performance is to run it on a faster computer, but there’s a limit to how many instructions per second even a fast CPU can execute.
Another approach is to run different parts of the program on different processors. Some computers have multiple processors and many these days have multiple cores, separate central processing units (CPUs) on a single chip. Two core systems are the norm these days and processors with four, eight, or even more cores are available.
To execute commands on different CPUs, a .NET application creates multiple threads. A thread is the smallest unit of code to which an operating system allocates CPU time. In multithreading, a single process has multiple threads of execution. If the system has multiple CPUs, the threads can run in parallel on different CPUs.
Get C# 5.0 Programmer's Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.