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 ...

Get Seven Concurrency Models in Seven Weeks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.