O'Reilly logo

Programming F# 3.0, 2nd Edition by Chris Smith

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 9. Asynchronous and Parallel Programming

“Parallel programming” frightens many developers, as the term has become synonymous with complexity and difficult-to-find bugs. However, with the libraries and language features available to F#, any anxiety over parallel programming is misplaced.

In fact, even if parallel programming were difficult—which I contend it is not—it is still worth studying because without it you simply cannot take advantage of your hardware’s potential.

This chapter focuses 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 define some of the domains related to “parallel programming”:

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 between processing resources in order to speed up execution. For example, converting a song into an MP3 can be parallelized—dividing the song into pieces and converting each segment in parallel.

Reactive programming

Reactive ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required