You are previewing Programming F#.

Programming F#

Cover of Programming F# by Chris Smith Published by O'Reilly Media, Inc.
O'Reilly logo

Chapter 11. Asynchronous and Parallel Programming

The reason for mastering asynchronous and parallel programming is that without it, you simply cannot take advantage of your hardware’s potential. This is especially true in intensive CPU-bound domains, like technical computing. Previously there was a good reason for not writing programs in an asynchronous or parallel fashion: added complexity and the risk of introducing bugs. However, with the great libraries available in Visual Studio 2010, combined with a side effect–free style of functional programming, this concern has been elegantly mitigated.

This chapter will focus on how to speed up computation in F# using asynchronous and parallel programming. By the end of this chapter, you will be able to execute code in different contexts (threads), use the F# asynchronous workflows library for mastering asynchronous programming, and also take advantage of the Parallel Extensions to .NET.

Before we begin, let’s first examine what exactly asynchronous and parallel programming mean and why they matter.

Asynchronous programming

Asynchronous programming describes programs and operations that once started are executed in the background and terminate at some “later time.” For example, in most email clients, new emails are retrieved asynchronously in the background so the user doesn’t have to force checking for new mail.

Parallel programming

Parallel programming is dividing up work among processing resources in order to speed up execution. For example, ...

The best content for your career. Discover unlimited learning on demand for around $1/day.