Transactional memory¶
Category: Lock-free · Status: stub
One line: Running a block of memory reads and writes as a transaction that either commits atomically or rolls back and retries, instead of taking locks.
Also called: STM, software transactional memory.
How it connects¶
flowchart LR
n_deadlock["Deadlock"]
n_mutex["Mutex"]
n_transactional_memory["Transactional memory"]
n_mutex ---|or| n_transactional_memory
n_transactional_memory -->|prevents| n_deadlock
classDef center stroke-width:3px
class n_transactional_memory center
classDef outside stroke-dasharray: 4 3
class n_deadlock,n_mutex outside
- Helps prevent: Deadlock
- An alternative to: Mutex
- See also: Concurrency models, Multi-version concurrency control
In each language¶
| C++ | The experimental Transactional Memory TS ↗: synchronized blocks run as if under a global lock, atomic blocks run as transactions |
| Haskell | Control.Monad.STM ↗: atomically runs a series of STM actions as one transaction, and retry abandons it when the TVar values it has seen mean it should not continue |
| Elsewhere | Clojure refs ↗ share mutable storage locations safely through software transactional memory |
Where to read more¶
- In the books: Programming Concurrency on the JVM, Venkat Subramaniam — ch. 6, 'Introduction to Software Transactional Memory'
- In the books: Learning Concurrent Programming in Scala, Aleksandar Prokopec — ch. 7, 'Software Transactional Memory'
- In the books: Parallel and Concurrent Programming in Haskell, Simon Marlow — ch. 10, 'Software Transactional Memory'
- In the books: Concurrent Programming: Algorithms, Principles, and Foundations, Michel Raynal — ch. 10, 'Transactional Memory'
- In the books: The Art of Multiprocessor Programming, Maurice Herlihy, Nir Shavit — ch. 18, 'Transactional Memory'
- In the books: Concurrency with Modern C++, Rainer Grimm — ch. 6, 'The Future: C++20/23' → 'Transactional Memory'
- Reference: Wikipedia: Software transactional memory ↗