Software Transactional Memory

The separation of identity from state helps STM solve the two major concerns with synchronization: crossing the memory barrier and preventing race conditions. We’ll first look at STM in the context of Clojure and then use it in Java.

Clojure removes the menacing details of memory synchronization (see Programming Clojure [Hal09] and The Joy of Clojure [FH11]) by placing access to memory within transactions. Clojure keenly watches over and coordinates the activities of threads. If there are no conflicts—for example, threads working with different accounts—then no locks are involved, and there are no delays, resulting in maximum concurrency. When two threads try to access the same data, the transaction manager steps ...

Get Programming Concurrency on the JVM 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.