LearnViz CompSci
Home / Learn / Concurrency & Parallelism / Software Transactional Memory

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

How to study this topic

  1. Read the explanation above and restate the definition in your own words.
  2. Open the interactive lesson and answer its mini quiz.
  3. Read the common pitfall, then write a short example that avoids it.
  4. 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?
Treating memory updates like database transactions. It belongs to Concurrency & Parallelism and is an intermediate-level topic.
Where do people use Software Transactional Memory?
Concurrent data structures with complex invariants, prototyping and languages emphasizing safe concurrency use STM.
What is the most common mistake with Software Transactional Memory?
Transactions must be free of irreversible side effects such as I/O, since they may re-execute.
What should I learn before this topic?
Start with ABA Problem, the topic just before it in Concurrency & Parallelism.
How can I practice it?
Answer the mini quiz in the interactive lesson, then take the Concurrency & Parallelism quiz.
Is Software Transactional Memory hard to learn?
It is an Intermediate topic. Be comfortable with the Beginner topics in this area first, then read the common pitfall carefully, since it is where most mistakes happen.
How long does it take to learn Software Transactional Memory?
Most learners can read the explanation and finish the interactive lesson in under an hour. Fluency comes from applying the idea, so plan a few short practice sessions with the quiz.
Which topics are related to Software Transactional Memory?
ABA Problem, Data Parallelism, Wait-Free Algorithms are closely connected. The full list is in the related topics section of this page.
What should I study after Software Transactional Memory?
Continue with Data Parallelism, the next topic in Concurrency & Parallelism.

Related topics