Writing multithreaded programs is not an easy task. Such programs are often difficult to reason about and debug. Sometimes, they provide different output due to changes in the execution order. Yet many programmers write multithreaded software, because today's demands require utilizing available CPU cores.
In Java, developers can use threads and locks. Such tools are not easy to use. We can see this by examining how thick the books on concurrency in Java[1] are. While Clojure does not provide a silver bullet to solve all concurrency issues, it does provide well-thought-out tools to manage multithreading.
In this chapter, we will do the following:
- Explain why concurrency is important in Clojure
- Examine the often overlooked difference between concurrency and parallelism
- Discuss problems with mutable states
- Explore Clojure's approach to...