In this chapter, we elaborated on achieving task parallelism using TPL. We started by introducing how to move sequential loops to parallel using some built-in methods provided by TPL, such as Parallel.Invoke, Parallel.For, and Parallel.ForEach. Next, we discussed how to get maximum utilization out of the available CPU resources by understanding the degree of parallelism and partitioning strategies. Then, we discussed how to cancel and break out of parallel loops using built-in constructs such as cancellation tokens, Parallel.Break, and ParallelLoopState.Stop. At the end of this chapter, we discussed various thread storage options that are available in TPL.
The TPL provides a few very exciting options that we can use to achieve data parallelism through the parallel implementation of For and ForEach loops. Along with features such as ParallelOptions and ParallelLoopState...