Home Knowledge Base Software Transactional Memory (STM)

Software Transactional Memory (STM) is a concurrency control mechanism that allows memory operations to be grouped into atomic transactions — a transaction either commits (all changes visible atomically) or aborts (no changes visible), without explicit locks.

The Transaction Analogy

STM Semantics

atomic {
    x = x + 1;          // Read x into transaction local copy
    y = y - 1;          // Read y
    // All changes visible atomically when block exits
}

How STM Works

1. Speculative execution: Transaction runs speculatively on thread-local copies. 2. Read/write logging: Track all addresses read and written. 3. Validation: Before commit, check read set is still valid (no other thread modified reads). 4. Commit or Abort: Valid → commit writes atomically. Invalid → abort + retry.

STM vs. Locks

AspectLocksSTM
DeadlockPossibleImpossible
ComposabilityHardNatural (nest transactions)
ScalabilityGood under low contentionGood under low contention
OverheadLow (fast path)Higher (log overhead)
Priority inversionPossibleNo

Hardware Transactional Memory (HTM)

Practical STM Implementations

Limitations

STM offers a higher-level, composable alternative to lock-based concurrency — particularly valuable for complex data structure updates where lock granularity is difficult to determine correctly.

software transactional memorystmtransactional memoryoptimistic concurrencyatomic block

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.