Almost every server or desktop application nowadays runs concurrently over many CPU cores. Once the result of a limitation on increasing single-processor speed, this becomes an opportunity to organize our applications in new ways. An application becomes a collection of tasks that run in dedicated threads. For multithreading, we can use either operating system threads or library threads. The latter are lightweight, so we can run many of them. Threads work concurrently, so we need to synchronize them.
In this chapter, we’ll discuss Haskell approaches to develop concurrent applications around threads. We’ll start with a discussion of Haskell mechanisms to run computations concurrently. We are interested in both low-level mechanisms available to Haskell developers from the base package and more sophisticated high-level tools provided by other libraries. Once we can run threads, we need them to communicate with each other. We’ll discuss how we do that in Haskell in the second section of the chapter.