Stephen Toub - MSFT

Partner Software Engineer, .NET

Stephen Toub is a developer on the .NET team at Microsoft.

Post by this author

Interested in parallel computing? We’re hiring!

If you're reading this post, you most likely have an interest in parallel or distributed computing, writing concurrent software, and the like.  Take that interest a step further, and help us make the manycore era a successful reality by coming to work on the Parallel Computing Platform team at Microsoft.We currently have several positions...

TaskCreationOptions.PreferFairness

One of the ways in which the Task Parallel Library achieves good performance is through “work-stealing”.  Work-stealing is supported in the .NET 4 ThreadPool for access through the Task Parallel Library and its default scheduler.  This manifests as every thread in the ThreadPool having its own queue for work; when that ...

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

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

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

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

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

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(() => { &...

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

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