Day 3: In Depth
We’ve now seen all of the ingredients of the “Clojure Way.” Today we’ll look at some more involved examples of those ingredients in use and gain some insights into how to choose between atoms and STM when faced with a particular concurrency problem.
Dining Philosophers with STM
To start off, we’ll revisit the “dining philosophers” problem we examined in Chapter 2, Threads and Locks, and construct a solution using Clojure’s software transactional memory. Our solution will be very similar to (but, as you’ll soon see, much simpler than) the condition-variable-based solution from Condition Variables.
We’re going to represent a philosopher as a ref, the value of which contains the philosopher’s current state (either :thinking ...
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