Loops in the Age of Concurrency

Looked at from a different perspective, loop constructors are essentially a source of tasks. If every iteration of a loop is independent from another iteration’s state, there’s no reason the individual iterations can’t be run in parallel. In the age of multicore processors on every desk, better ways to unleash the hardware’s power are a much-searched-for treasure. The new System.Threading namespace additions in .NET 4.0 provide for this in various ways, one of which is the concept of parallel loop constructs. We look at this in more detail in Chapter 30, “Task Parallelism and Data Parallelism.” Figure 7.23 shows the Parallel class’s static methods.

FIGURE 7.23 The System.Threading.Parallel type’s parallel loop ...

Get C# 5.0 Unleashed 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.