Skip to Main Content
Parallel and Concurrent Programming in Haskell
book

Parallel and Concurrent Programming in Haskell

by Simon Marlow
July 2013
Intermediate to advanced content levelIntermediate to advanced
322 pages
8h 43m
English
O'Reilly Media, Inc.
Content preview from Parallel and Concurrent Programming in Haskell

Chapter 13. Parallel Programming Using Threads

We have been discussing concurrency as a means to modularize programs with multiple interactions. For instance, concurrency allows a network server to interact with a multitude of clients simultaneously while letting you separately write and maintain code that deals with only a single client at a time. Sometimes these interactions are batch-like operations that we want to overlap, such as when downloading multiple URLs simultaneously. There the goal was to speed up the program by overlapping the I/O, but it is not true parallelism because we don’t need multiple processors to achieve a speedup; the speedup was obtained by overlapping the time spent waiting for multiple web servers to respond.

But concurrency can also be used to achieve true parallelism. In this book, we have tried to emphasize the use of the parallel programming models—Eval, Strategies, the Par monad, and so on—for parallelism where possible, but there are some problems for which these pure parallel programming models cannot be used. These are the two main classes of problem:

  • Problems where the work involves doing some I/O
  • Algorithms that rely on some nondeterminism internally

Having side effects does not necessarily rule out the use of parallel programming models because Haskell has the ST monad for encapsulating side-effecting computations. However, it is typically difficult to use parallelism within the ST monad, and in that case probably the only solution is to drop ...

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.
Start your free trial

You might also like

Haskell High Performance Programming

Haskell High Performance Programming

Samuli Thomasson
Haskell Cookbook

Haskell Cookbook

Yogesh Sajanikar
Haskell in Depth

Haskell in Depth

Vitaly Bragilevsky

Publisher Resources

ISBN: 9781449335939Supplemental ContentErrata Page