9 Concurrent application framework

This chapter covers

  • How to build a general-purpose concurrent application framework
  • Why multithreading and complexity are hard yet very important
  • Why we abstract threads and how to do this in a thread-safe manner
  • How to incorporate software transactional memory into a framework

This chapter opens the final part of this book. Going forward, we will discuss more common matters of software design as they relate to real-world tasks we may encounter in a regular software company. In the remaining chapters, we’ll be constructing an application framework suitable for building multithreaded, concurrent web servers and command-line applications. We’ll talk about free monads as a way to organize a testable, simple, and maintainable foundation for business logic code. Of course, we can’t ignore the important themes such as SQL and key–value (KV) database support, logging, state handling, concurrency and reactive programming, error handling, and so forth. We’ll also learn new design patterns and architecture approaches, such as final tagless/mtl, the ReaderT pattern, and others, so we can navigate between the solutions with confidence.

9.1 Multithreaded applications

9.1.1 Why is multithreading hard?

9.1.2 Bare threads

9.1.3 Separating and abstracting the threads

9.1.4 Threads bookkeeping

9.2 Software transactional memory

9.2.1 Why STM is important

9.2.2 STM-powered runtime of the framework

9.2.3 Incorporating STM

Summary