O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

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

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 ...

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