If It Hurts, Stop Doing It
The rules about locking that we discussed in Chapter 2, Threads and Locks, apply only to data that is both shared between threads and might change—in other words shared mutable state. Data that doesn’t change (is immutable) can be accessed by multiple threads without any kind of locking.
This is what makes functional programming so compelling when it comes to concurrency and parallelism—functional programs have no mutable state, so they cannot suffer from any of the problems associated with shared mutable state.
In this chapter we’re going to look at functional programming in Clojure,[9] a dialect of Lisp that runs on the JVM. Clojure is dynamically typed; and if you’re a Ruby or Python programmer, you’ll feel ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access