Using the Task Parallel Library (TPL)
In this chapter, we will be working with TPL to enhance the performance of our programs by making use of the available processor power on a machine.
We learned how to write threads and execute them in Chapter 14, Multi-Threaded Programming. When multiple threads are running on a single processor, providing the illusion that they are running in parallel, they are running concurrently.
When threads run concurrently, the processor uses a scheduling algorithm and/or interrupts to determine the switching and prioritization between threads. Parallel programming, however, runs different threads on different processors so that threads execute in parallel to each other with a reduced need for switching and thread interrupts.
As its name suggests, TPL is used to run tasks in parallel. Tasks are run in parallel by running each task against a separate core of the computer’s processor. So, for example, say your computer has four cores and you...