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.