Chapter 7. Concurrency and Performance
Writing concurrent programs that are correct is hard: subtle race conditions, resources blocked by another thread, asynchronous exceptions, and so on. Basically, a lot can go wrong. Remember that, whereas parallelism points to execution model (multiple threads running simultaneously), concurrency is more like a paradigm: multiple threads working together, intertwined. However, concurrent threads are often run in parallel for responsiveness and performance reasons.
In this chapter, we will write concurrent Haskell programs making use of light-weight threads and type-safe concurrency primitives like MVars. For complex programs, we will learn to build atomic transactions with Software Transactional Memory (