O'Reilly logo

C# 5.0 Programmer's Reference by Rod Stephens

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required