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










