Concurrency is one of the biggest challenges the industry is working on now days. Anders mentioned about the details of this in his talk ‘Future of C#’ at PDC.
So what’s the problem about?
Concurrency is about doing multiple tasks simultaneously. Most of our applications today do this asynchronous programming using multiple threads/processes but they all work on a Single CPU.
This worked fine until now as the single CPU’s were getting faster and faster as per the Moore’s Law and hence the applications would also just run faster without us having to do anything.
But now we are facing some physical limitations increasing the speed of a Single CPU. So to increase the processing power we need to have multiple CPU’s in a single machine. Hence we are already getting many core machines with 2, 4, 8 to 64 CPU’s.
So how does this impact us as a Developer?
With this solution in place the traditional asynchronous programming isn’t going to help us scale our applications. We would have to create programs which can divide their workload into tasks that can be executed in parallel on Multiple CPU’s.
Parallel FX (PFX)
Microsoft is developing a number of technologies to simplify parallel programming. Parallel Extensions for the .NET Framework (PFX) is an example of this. It is a managed programming model for data parallelism, task parallelism, scheduling, and coordination on parallel hardware. This technology was first discussed by Anders Hejlsberg and Joe Duffy in Oct 2007 and was initially provided as an extension library but it’s now deeply integrated into the .Net Framework 4.0.Task Parallel Library (TPL)
The basic unit of parallel execution in the TPL is a ‘Task’. The Parallel.For() and Parallel.ForEach() static methods create a Task for each member of the source IEnumerable and distribute execution of these across the machine’s available processors using User Mode Scheduling.Parallel LINQ (PLINQ)
We can setup a LINQ query for parallel execution using PLINQ. We just need to wrap IEnumerable<T> in an IParallelEnumerable<T> by calling the AsParallel() extension method.Daniel Moth did an excellent presentation on PFX at Tech-Ed which you can watch here.
For more details you can go to the PFX Team blog site which contains lots of videos and tutorials on parallel programming.