Chapter 10. Mutation and concurrency

 

This chapter covers

  • Software transactional memory with multiversion concurrency control and snapshot isolation
  • When to use refs
  • When to use agents
  • When to use atoms
  • When to use locks
  • Vars and dynamic binding

Clojure’s main tenet isn’t the facilitation of concurrency. Instead, Clojure at its core is concerned with the sane management of state, and facilitating concurrent programming naturally falls out of that. Concurrency refers to designing systems using independently executing, logic processes (Pike 2012). A simple concurrent design is a single thread named Tom inserting data into a work queue, as shown in figure 10.1.

Figure 10.1. Tom, alone

Of course, although this is technically a concurrent design, having Tom work alone doesn’t achieve a high degree of concurrency. But if we add another thread to the mix as in figure 10.2, then the concurrency in the design begins to become more apparent.

Figure 10.2. Tom inserts data into the work queue

10.1. When to use refs

10.2. Refactoring with refs

10.3. When to use agents

10.4. When to use atoms

10.5. When to use locks

10.6. Vars and dynamic binding

10.7. Summary

sitemap