Learn the vocabulary of composing atomic memory updates that automatically retry on conflict instead of using explicit locks.
0 / 5 completed
1 / 5
A teammate describes a concurrency technique where a block of memory operations runs speculatively, and if another thread modified the same data concurrently, the whole block automatically retries instead of using explicit locks. What is this technique called?
Software transactional memory is exactly this: it lets a block of memory operations run speculatively as a transaction, and if a conflicting concurrent modification is detected, the transaction automatically aborts and retries, without the programmer writing explicit locks. A hash collision is an unrelated hash-table concept about two keys sharing a bucket. This speculative-retry-on-conflict approach is exactly why software transactional memory can replace manual locking for many composable concurrent operations.
2 / 5
During a design review, the team adopts software transactional memory for a bank account transfer routine, specifically so that transferring between two accounts either fully applies or automatically retries if another transaction conflicts, without deadlock-prone manual locks. Which capability does this provide?
Software transactional memory here provides composable, deadlock-free atomic updates, since transactions automatically retry on conflict instead of requiring the programmer to acquire multiple locks in a careful order to avoid deadlock. Manually acquiring two locks in whichever order the code happens to acquire them is exactly how classic lock-ordering deadlocks occur between concurrent transfers. This automatic-retry-on-conflict behavior is exactly why software transactional memory is favored for composing multiple atomic updates safely.
3 / 5
In a code review, a dev notices a fund-transfer routine acquires two separate account locks in an order that depends on which account object was allocated first, rather than running the transfer as a single software-transactional-memory transaction. What does this represent?
This is a missed software-transactional-memory opportunity, since running the transfer as a single transaction would let it automatically retry on conflict instead of risking a lock-ordering deadlock. A cache eviction policy is an unrelated concept about discarded cache entries. This allocation-order-locking pattern is exactly the kind of deadlock risk a reviewer flags once composable atomic updates are the goal.
4 / 5
An incident report shows two concurrent fund transfers deadlocked because each acquired one account's lock first and then blocked waiting for the other account's lock held by the other transfer. What practice would prevent this?
Rewriting the transfer as a software-transactional-memory transaction ensures a detected conflict causes an automatic retry instead of both transfers blocking on each other's locks. Continuing to acquire the two account locks in whichever order the transfer happens to encounter them regardless of how often deadlocks occur is exactly what caused the deadlock described in this incident. This retry-on-conflict approach is the standard fix once lock-ordering deadlocks are confirmed to occur between concurrent transfers.
5 / 5
During a PR review, a teammate asks why the team reaches for software transactional memory instead of fine-grained manual locking, given that manual locks are already well understood by the team. What is the reasoning?
Software transactional memory trades some runtime overhead for automatic conflict detection and retry, making composed atomic operations deadlock-free, while manual locking is familiar but requires careful lock ordering that becomes error-prone as more locks are composed. This is exactly why software transactional memory is favored when multiple atomic operations must be composed safely, while simple manual locking remains acceptable for a single, well-scoped critical section.