Posts by this author

Jun 30, 2009
Post comments count0
Post likes count0

Asynchronous methods, C# iterators, and Tasks

More and more, developers are realizing the significant scalability advantages that asynchronous programming can provide, especially as it relates to I/O. Consider an application that needs to copy data from one stream to another stream, such as is being done in the following synchronous implementation: static void CopyStreamToStream(Stream input...

.NET Parallel Programming
Jun 24, 2009
Post comments count0
Post likes count0

Parallel For Loops over Non-Integral Types

In a previous post, it was demonstrated how for loops with very small loop bodies could be parallelized by creating an iterator over ranges, and then using Parallel.ForEach over those ranges.  A similar technique can be used to write parallel loops over iteration spaces of non-integers.  For example, let’s say I wanted to paralleliz...

.NET Parallel Programming
Jun 19, 2009
Post comments count0
Post likes count1

Tasks and the Event-based Asynchronous Pattern

As has been discussed previously, one of the new features in the Task Parallel Library is TaskCompletionSource<TResult>, which enables the creation of a Task<TResult> that represents any other asynchronous operation.  There are a wide variety of sources in the .NET Framework for asynchronous work.  One comes from components th...

.NET Parallel Programming
Jun 9, 2009
Post comments count0
Post likes count0

Tasks and the APM Pattern

The Asynchronous Programming Model (APM) in the .NET Framework has been around since .NET 1.0 and is the most common pattern for asynchrony in the Framework.  Even if you’re not familiar with the name, you’re likely familiar with the core of the pattern.  For a given synchronous operation Xyz, the asynchronous version manifest...

.NET Parallel Programming
Jun 6, 2009
Post comments count0
Post likes count0

Achieving Speedups with Small Parallel Loop Bodies

The Parallel class represents a significant advancement in parallelizing managed loops.  For many common scenarios, it just works, resulting in terrific speedups.  However, while ideally Parallel.For could be all things to all people, such things rarely work out, and we’ve had to prioritize certain scenarios over others.One area Par...

.NET Parallel Programming
Jun 3, 2009
Post comments count0
Post likes count0

Mechanisms for Creating Tasks

The core entity in the Task Parallel Library around which everything else revolves is System.Threading.Tasks.Task.  The most common way of creating a Task will be through the StartNew method on the TaskFactory class, a default instance of which is exposed through a static property on Task, e.g. var t = Task.Factory.StartNew(() => {  &n...

.NET Parallel Programming
Jun 2, 2009
Post comments count2
Post likes count2

The Nature of TaskCompletionSource

The Task Parallel Library is centered around the Task class and its derived Task<TResult>. The main purpose of these types is to represent the execution of an asynchronous workload and to provide an object with a means to operate on that workload, whether it be to wait for it, to continue from it, or the like. The primary type of asynchronous...

.NET Parallel Programming
Jun 1, 2009
Post comments count0
Post likes count0

CLR 4 – Inside the ThreadPool

As we’ve mentioned previously, the .NET ThreadPool has undergone some serious renovations in .NET 4, improvements on which the Task Parallel Library and PLINQ both rely.  Erika Parsons and Eric Eilebrecht are the PM and developer on the CLR team for the ThreadPool, and they’re featured in a great new Channel9 video covering the .NE...

.NET Parallel Programming
Jun 1, 2009
Post comments count0
Post likes count0

Tasks and Unhandled Exceptions

Prior to the .NET Framework 2.0, unhandled exceptions were largely ignored by the runtime.  For example, if a work item queued to the ThreadPool threw an exception that went unhandled by that work item, the ThreadPool would eat that exception and continue on its merry way.  Similarly, if a finalizer running on the finalizer thread threw a...

.NET Parallel Programming
May 29, 2009
Post comments count0
Post likes count1

ParallelOptions.MaxDegreeOfParallelism vs PLINQ’s WithDegreeOfParallelism

We exert a good deal of effort ensuring that the APIs we provide are consistent within Parallel Extensions as well as with the rest of the .NET Framework.  This is from many angles, including behavior and general design, but also naming.  So when there are slight differences in naming, it raises questions.One occurrence of such a slight n...

.NET Parallel Programming