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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access