Created by bagwell on 2010-12-09. Updated: 2010-12-09, 16:57

The Scala STM Expert group has announced that the first version of support for STM in Scala will be available with Scala 2.9 or shortly after. The team has provided a fast, lightweight and self contained STM library for Scala. For those of you interested in using the pre-release version, finding out more about the project or giving feedback should visit their very informative Scala-stm site.The effort was inspired by the STMs in Haskell and Clojure and provides a reference implementation based on CCSTM.

Scala STM is for programmers whose threads or actors need to coordinate access to shared data. These may be for example a list of active connections or a cache in a server or a partial result or worker thread status in a client.

Software transactional memory is a mediator that sits between a critical section of your code (the atomic block) and the program’s heap. The STM intervenes during reads and writes in the atomic block, allowing it to check and/or avoid interference other threads. If the loads and stores of multiple threads have become interleaved, then all of the writes of the atomic block are rolled back and the entire block is retried. If the accesses by the critical section are not interleaved, then it is as if they were done atomically and the atomic block can be committed. Other threads or actors can only see committed changes.