O'Reilly logo

Clojure Data Analysis Cookbook - Second Edition by Eric Rochester

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

Managing program complexity with STM

The basis of Clojure's concurrency is its STM system. Basically, this extends the semantics of database transactions to the computer's memory.

For this recipe, we'll use the STM to calculate the families per housing unit from a piece of U.S. census data. We'll use future-call to perform the calculations in the thread pool and spread the execution over multiple cores. Afterwards, we'll go into more detail about how the STM works in general, and how it's applied in this particular recipe.

Getting ready

To prepare for this recipe, we first need to list our dependencies in the Leiningen project.clj file:

(defproject concurrent-data "0.1.0-SNAPSHOT" :dependencies [[org.clojure/clojure "1.6.0"] [org.clojure/data.csv ...

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