Intermediate Topic 29 of 51 Concurrency & Parallelism
Software Transactional Memory
Treating memory updates like database transactions.
How it works
Software transactional memory lets programmers write concurrent code by marking blocks as atomic transactions: reads and writes to shared memory inside are tracked, and at commit the runtime checks for conflicts with other transactions, committing all changes atomically or aborting and retrying. It avoids explicit locks and deadlocks, composes better than locks and supports operations such as retry and orElse. Implementations use optimistic versioning, logs and validation. Haskell's STM and Clojure's refs are well-known examples.
Where it is used
Concurrent data structures with complex invariants, prototyping and languages emphasizing safe concurrency use STM.
Common pitfall
Transactions must be free of irreversible side effects such as I/O, since they may re-execute. Overhead from logging and validation can make performance poor, and long transactions or high contention cause repeated aborts. Few mainstream languages have mature STM. Keep transactions small, avoid side effects inside and measure contention.
Where it fits in the course
Software Transactional Memory is topic 29 of 51 in Concurrency & Parallelism, rated Intermediate. It follows ABA Problem. The next topic is Data Parallelism.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Concurrency & Parallelism quiz.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Concurrency & Parallelism quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Software Transactional Memory?
Where do people use Software Transactional Memory?
What is the most common mistake with Software Transactional Memory?
What should I learn before this topic?
How can I practice it?
Is Software Transactional Memory hard to learn?
How long does it take to learn Software Transactional Memory?
Which topics are related to Software Transactional Memory?
What should I study after Software Transactional Memory?
Related topics
- ABA Problem (Concurrency & Parallelism)
- Data Parallelism (Concurrency & Parallelism)
- Wait-Free Algorithms (Concurrency & Parallelism)
- Task Parallelism (Concurrency & Parallelism)
- Software Development Life Cycle (Software Engineering)
- Manual Memory Management (Languages & Compilers)
- Software Documentation (Software Engineering)