.NET Parallel Programming

All about Async/Await, System.Threading.Tasks, System.Collections.Concurrent, System.Linq, and more…

Latest posts

Custom Loop with Arbitrary Initialization, Condition, and Update
Jul 27, 2008
0
0

Custom Loop with Arbitrary Initialization, Condition, and Update

Stephen Toub - MSFT
Stephen Toub - MSFT

The Parallel.For loop construct provided by Parallel Extensions is focused on providing a parallel alternative to the common sequential pattern of a for loop that iterates over a range of numbers.  However, the for loop construct in a language like C# is not limited just to numbers and iterating over ranges.  It supports arbitrary initialization, condition, and update expressions, for example: for(var i = init(); cond(i); i = upd(i)) { Use(i); } There isn't any built-in Parallel construct that supports this pattern. However, one of our goals with Parallel Extensions is to provide the foundational supp...

Useful Abstractions Enabled with ContinueWith
Jul 24, 2008
0
1

Useful Abstractions Enabled with ContinueWith

Stephen Toub - MSFT
Stephen Toub - MSFT

In the June 2008 CTP of Parallel Extensions to the .NET Framework, we introduced the ContinueWith method on both Task and Future<T>.  ContinueWith is, in effect, a callback, very much like events in .NET.  With events, a causal action results in the event being raised, which by default triggers all of the delegates registered with the event to be invoked.  ContinueWith supports this, but rather than just registering the callback, it also provides back a Task or Future<T> that represents the callback; that returned Task or Future<T>'s lifecycle is tied specifically to the callback ...

Fork/Join parallelism with .NET CountdownEvent
Jun 21, 2008
0
0

Fork/Join parallelism with .NET CountdownEvent

cristina manu
cristina manu

A common asynchronous pattern in code today is the pattern known as fork/join parallelism. This typically manifests by starting n pieces of work and later joining with that work. The existing set of the .NET synchronization primitives does not offer a simple solution for handling this common scenario. It can be achieved, for example, by using a ManualResetEvent and a separate count that’s manipulated with Interlocked operations, but the implementations are not trivial, and they easily could lead to race conditions and other potential problems. Parallel Extensions to the .NET Framework introduces several n...

Coordination Data Structures Overview
Jun 18, 2008
0
0

Coordination Data Structures Overview

Emad Omara
Emad Omara

The June 2008 CTP of Parallel Extensions provides the first look at its 3rd major piece, a set of coordination data structures we lovably refer to as CDS. It contains lightweight and scalable thread-safe data structures and synchronization primitives.  There are of course already many synchronization primitives present in the System.Threading namespace of the .Net Framework, such as ManualResetEvent, Monitor, Mutex, and Semaphore: these types are still very useful for developing multithreading applications, and in fact Parallel Extensions relies on many of them, but sometimes higher-level or lighter-weight p...

Introducing ConcurrentStack
Jun 18, 2008
0
0

Introducing ConcurrentStack

cristina manu
cristina manu

A common problem users run into when writing parallel applications is the lack of the thread-safety support in the .NET collection classes. Users typically need to implement their own synchronization mechanism for achieving the goal of safely reading/writing data to the same shared collection. A largely deprecated solution was to use the synchronized collections introduced in the .NET Framework 1.0, or to use the SyncRoot mechanism exposed through the ICollection interface. However, both of these approaches are not recommended to be used, for a variety of reasons, including less-than-ideal performance, but also...

PLINQ Ordering
Jun 11, 2008
0
0

PLINQ Ordering

essey
essey

There is a natural tension between ordering and performance in a parallel partitioning system such as PLINQ, which we addressed as guidance in the Dec07 CTP documentation:  “Although you can opt into ordering, this does come at a cost to performance because it constrains the options which PLINQ can use for executing a query, so it is better to avoid it in general if performance is your main concern. A better approach is to avoid assumptions on ordering in your programs where possible, or to explicitly sort elements in your query. This is consistent with the approach that most relational databases take....

Parallel Extensions Demo Fun on Channel 9
Jun 11, 2008
0
0

Parallel Extensions Demo Fun on Channel 9

Stephen Toub - MSFT
Stephen Toub - MSFT

When I was at TechEd 2008 Developer last week, I met up with the great Dan Fernandez from Channel 9 to show off Parallel Extensions and to demonstrate some of the sample applications included with our June 2008 CTP.  The cameras were at the ready, so you can see the demonstrations, too: Thanks, Dan!

Image Colorizer Sample in the June 2008 CTP
Jun 9, 2008
0
0

Image Colorizer Sample in the June 2008 CTP

Mike Liddell
Mike Liddell

Continuing the tour of the samples included in the Parallel Extensions June 2008 CTP, we now turn our attention to the "Image Colorizer" application.   This sample uses the following constructs from Parallel Extensions: System.Threading.Parallel.For() and also the following from the standard .NET libraries: System.ComponentModel.BackgroundWorker System.Threading.Interlocked.Add()   The Image Colorizer was originally written by Stephen Toub to demonstrate Tablet PC APIs functionality (see https://msdn.microsoft.com/en-us/library/bb332387.aspx) and requires the Microsoft.Ink.DLL to compile.  If you ...

Announcing the “Parallel Programming in Native Code” Blog
Jun 7, 2008
0
0

Announcing the “Parallel Programming in Native Code” Blog

essey
essey

Our colleagues working on native concurrency have just launched the Parallel Programming in Native Code blog.  We’re all on the same team and work really closely to ensure that the right programming models are exposed both for managed and native consumers, so you will be able to use your language of choice. Here’s a little bit from the Welcome post explaining what they’re all about. “…We’re looking to help overcome these barriers and improve productivity for C++ developers.  We want to make expressing concurrency easier by adding abstractions for describing...