liveBook · Manning

Multithreading

As explained in Functional Design and Architecture: Examples in Haskell

Multithreading is the concurrent execution of multiple threads within a process.

Multithreading executes multiple threads within a process, but its real difficulty lies in designing readable, maintainable systems around shared mutable state and concurrent interactions. section 9.1 section 9.1.1

Concurrent designs must account for several interacting failure modes:

  • Race conditions can corrupt shared data or leave it invalid. section 9.1.1
  • Deadlocks stop progress when threads wait for one another, while livelocks consume resources without advancing. section 9.1.1
  • Starvation, resource leakage, resource overflow, unclear lifetimes, and incorrect exception handling complicate production reliability. section 9.1.1

A practical architecture limits direct thread manipulation and chooses state mechanisms deliberately. IORefs, MVars, and STM TVars provide different choices; composable STM can reduce coordination complexity, while bare threads remain a limited resource requiring careful organization and cleanup. section 9.1 section 9.3

Concurrent application framework

A general-purpose framework can support multithreaded web servers and command-line applications while placing concurrency behind safer abstractions. STM can provide thread-safe state handling at the implementation layer, and free monads can keep business logic testable and maintainable. section 9.0 section 9.3

How Functional Design and Architecture: Examples in Haskell covers it

How deep it goes
Explains major failure modes and state primitives, then stops short of comprehensive multithreading internals while comparing STM with bare threads.
Examples
Uses race conditions, deadlocks, livelocks, starvation, leakage, overflow, and exception-handling failures as concrete problem cases.
What you can do after
Diagnose concurrency risks, choose among IORefs, MVars, and STM TVars, and organize threads with safer resource handling.
How it connects
Connects multithreading to concurrency, shared mutable state, STM, IORefs, MVars, TVars, resource management, and application architecture.

Also explained in

Compare how 11 books explain multithreading →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Functional Design and Architecture: Examples in Haskell. The section links point to the parts of the book it draws on.