When I’m talking to people about the new things that Visual Studio 2010 and ASP.NET 4.0 bring, and the easy it is to write code to be executed in parallel, many people just don’t care. They see it as if it wasn’t related to them. It’s true that some kind of applications don’t really need this type of optimization… but that’s not an excuse to try to take advantage of our hardware as much as possible. From several years ago the most common thing in any computer is to have at least two processor cores. As a matter of fact, we’re starting to see now desktop computers with 8-core processors. The trend is to have an ever-increasing number of cores in our computers. This means that any application will have the chance to work in an environment where more than one thread can be executed simultaneously. Besides, nowadays if you want your software to perform faster, you can no longer just move it to a machine with a faster processor and forget about it. We’re approaching the maximum speed a processor can get, so improvements in next CPUs will come from the side of more threads, not a higher clock-rate. I think parallel programming  is a key concept all programmers should care about. ASP.NET 4.0 and Visual Studio 2010 bring new libraries, types and tools to ease multi-core development. ASP.NET 4.0 includes the new “Parallel Extensions”, which are formed by:

  • Task Parallel Library: this new library, included in the namespace System.Threading.Tasks.Parallel, has new elements to execute tasks in parallel automatically. It’s got, for example, a parallel For loop, and a parallel ForEach loop.
  • Parallel LINQ Execution Engine: as you can guess, it’s a parallelized version of Linq to Objects. It’s the same thing, except that it will run in parallel whenever possible.
  • Coordination Data Structures: it’s a set of primitives for sincronization and thread-safe collections. For example, we have thread-safe dictionaries, stacks and buffers, and special objects for thread sincronization, such as SpinWait or SpinLock.

Now, the good part about these parallel extensions is that it gets extremely easy to do parallel programming. Just by using these new features, your code will escalate to use as many parallel threads as possible. For example, in a machine with just one processor all your code will execute sequentially, just as always. But, in an 8-core-processor computer, your code will be broken down into 8 different threads, and they all will execute your code in parallel –assuming all 8 cores are available, of course. You can learn more this article from MSDN.

Related posts:

  1. Persistance layer: object-relational mapping tools
  2. ASP.NET 4.5 and Visual Studio 11
  3. Entity Framework
  4. Things to consider when using Entity Framework