Ditch Your (mut)ex, You Deserve Better
Postedabout 2 months agoActiveabout 2 months ago
chrispenner.caTechstory
calmmixed
Debate
20/100
ConcurrencySoftware Transactional MemoryMutexesProgramming
Key topics
Concurrency
Software Transactional Memory
Mutexes
Programming
The post discusses alternatives to mutexes, sparking a discussion on the merits of Software Transactional Memory as a replacement for traditional synchronization methods.
Snapshot generated from the HN discussion
Discussion Activity
Light discussionFirst comment
6h
Peak period
1
5-6h
Avg / period
1
Key moments
- 01Story posted
Nov 12, 2025 at 2:15 AM EST
about 2 months ago
Step 01 - 02First comment
Nov 12, 2025 at 7:51 AM EST
6h after posting
Step 02 - 03Peak activity
1 comments in 5-6h
Hottest window of the conversation
Step 03 - 04Latest activity
Nov 12, 2025 at 7:51 AM EST
about 2 months ago
Step 04
Generating AI Summary...
Analyzing up to 500 comments to identify key contributors and discussion patterns
ID: 45897225Type: storyLast synced: 11/20/2025, 2:24:16 PM
Want the full context?
Jump to the original sources
Read the primary article or dive into the live Hacker News thread when you're ready.
Sadly, the simplicity benefits it touts over Mutexes simply don't pan out. You still have to have some structure around your critical section, it forces you to still contend with partially-updated intermediate values, which mutexes spare you from.
Likewise, the composition issue isn't more solved with STM than with Mutexes. Implementations that wish to support re-entrant transactions still have overhead over those that don't, similar to the overhead a reentrant_mutex has over a regular mutex.
My favourite solution to the many-reader few-writer scenario is the rarely-supported "Upgradeable Shared Mutex". Like parking_lot's RwLock (https://docs.rs/lock_api/0.4.14/lock_api/struct.RwLock.html#...)
With an Upgradeable Shared Mutex one can take a simple shared read lock, an exclusive write lock, or an upgradeble read lock. The upgradeable read lock can then - without unlocking - be upgraded to an exclusive lock once you've prepared the writes you wish to do, keeping the exclusive section as short as possible. To avoid deadlock, the upgradeable read lock can exist concurrently with simple read locks, but not other upgradeable locks.