O'Reilly logo

Seven Concurrency Models in Seven Weeks by Paul Butcher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required