Skip to content

Fine-Grained Locking ​

A primary-source survey of how locks, condition variables and their asynchronous cousins are built today: the futex-word locks of Rust, Zig and glibc; the parking lots of WebKit, parking_lot and Go's runtime; the queue locks behind Abseil, nsync, Java's AbstractQueuedSynchronizer and Linux; the operating systems' wait-on-address primitives; the task-level primitives of tokio, smol, Seastar, Trio and kotlinx.coroutines; and the papers, from Concurrent ML in 1991 to combine-and-exchange locks in 2025, that bear on waiting across threads and fibers. Thirteen lock implementations, four OS primitives, four async runtimes, twelve papers, and two runnable benchmarks.

It is the evidence base for sparkles.base.sync — wait-on-address-based Mutex, Condition, Once, Event and Semaphore for D, @nogc nothrow, on Linux, Windows, macOS and FreeBSD — and for event-horizon's WaitWord, which lets fibers on a completion-based loop wait on a word another thread wakes.

This survey answers four questions:

  1. What should the mutex word be? A parking-lot lock — two bits plus a designated-waker bit — over a fixed table of address-keyed queues: faster than the three-state futex word once one waiter at a time is woken, and the only design that permits wait morphing and handoff. See comparison § (a).
  2. What condition-variable algorithm? Wait morphing: requeue waiters onto the mutex's queue, with exact notifications. See comparison § (b).
  3. How fair, and how much spinning? Barge, bound starvation by a count of failed wakes with a handoff to the designated waker, and spin briefly before parking. See comparison § (c).
  4. How do loop-resident fibers wait on a word? In the same parking lot: a queue node carries a thread's parker or a fiber's loop waker, so every primitive becomes fiber-aware on every OS. See comparison § (d).

Last reviewed: October 12, 2026

Master catalog ​

SubjectCategoryLanguage / OSPrimitive / contributionLink
Rust std::syncthread locksRust3-state futex mutex, sequence-counter condvar, queue-based fallbacks→
Zig std.Io syncthread locksZigfutex locks through the Io vtable; a parking futex on Windows→
glibc NPTLthread locksClll_lock, adaptive mutexes, the 2016 G1/G2 condvar→
parking_lotthread locksRustone-byte locks over a global hashed parking table; condvar requeue→
WebKit WTF::Lockthread locksC++two-bit locks, ParkingLot, randomized eventual fairness→
Go sync and sema.gothread locksGostarvation mode after 1 ms; the runtime's address-keyed semaphore treap→
Abseil absl::Mutexthread locksC++queue pointer in the word, Await predicates, Fer condvar transfer→
nsyncthread locksCpredicate waits without condvars; wake-count starvation bound; nsync_wait_n→
Folly synchronizationthread locksC++DistributedMutex combining, ParkingLot, fibers::Baton→
Java AbstractQueuedSynchronizerthread locksJavaCLH-style queue, LockSupport.park, virtual threads unchanged→
os_unfair_lockthread locksDarwinowner in the word, priority inheritance, no spinning→
SRWLOCK and CONDITION_VARIABLEthread locksWindowspointer-sized, zero-initialized; the 2005–2024 shared-mode bug→
Queue locks (MCS, CLH, qspinlock)thread locksLinux, paperslocal spinning, the MCS tail in a 32-bit word, HANDOFF, CNA→
Linux futexesOS waitLinuxfutex, PI, requeue, futex2, io_uring futex ops→
Windows WaitOnAddressOS waitWindowsuser-mode waiter table over thread alerts; IOCP bridges→
Darwin __ulock and os_syncOS waitDarwinprivate SPI, the macOS 14.4 public API, EVFILT_USER bridging→
FreeBSD _umtx_opOS waitFreeBSDUMTX_OP_WAIT_UINT_PRIVATE; libthr's user-space condvar queue→
tokio syncasyncRustintrusive FIFO semaphore; cancellation that passes the permit on→
smol event-listener / async-lockasyncRustone list for task wakers and thread unparkers; 500 µs starvation mode→
SeastarasyncC++shard-local primitives; membarrier wakeups→
TrioasyncPythona per-object ParkingLot; FIFO handoff; from_thread→
Reppy 1991 — CMLpaperMLfirst-class synchronous events; choose; the Parallel CML protocol→
von Behren et al. 2003 — CapricciopaperCuser-level threads over async I/O; the cost of the idle path→
Li & Zdancewic 2007paperHaskellthreads as a monad over an event loop→
Ziarek et al. 2011paperMLcomposable asynchronous events: register now, resume when matched→
Tardieu, Wang & Lin 2012paperX10work stealing with suspendable tasks→
Seo et al. 2018 — ArgobotspaperCuser-level threads and tasklets for HPC runtimes→
Enberg, Rao & Tarkoma 2019paperC++thread-per-core; the cross-core wakeup protocol and its lost-wakeup hazard→
Karsten & Barghi 2020paperC++M:N threading; benaphore idle sleep; one wakeup function→
Koval, Khalanskiy & Alistarh 2023 — CQSpaperKotlinfair, abortable, verified waiter queues; kotlinx.coroutines' Mutex, Semaphore→
Skazhenik et al. 2025paperC++spin → yield → suspend for locks under cooperative scheduling→
Skazhenik et al. 2026paper (Russian)C++the journal study: BackoffType for TTAS, MCS and HMCS on coroutines→
König, Epple & Becker 2025 — CESpaperC++combine-and-exchange: resume the waiter locally, requeue the releaser→

The concepts page defines the shared vocabulary, and the comparison answers the four questions.

Taxonomy ​

By where waiters live ​

WhereSubjects
The kernel, keyed by the lock wordRust std, Zig (Linux), glibc, os_unfair_lock
A user-space table keyed by addressparking_lot, WebKit, Go, Folly ParkingLot, WaitOnAddress
A queue hanging off the lockAbseil, nsync, Java AQS, queue locks, tokio, event-listener
The waiters' own stacksFolly DistributedMutex, Linux qspinlock
One thread's data structures (no sharing)Seastar, Trio, Enberg 2019

By what a fiber or task does while it waits ​

StrategySubjects
Kernel wait as a completionZig Io.Uring, Linux io_uring futex ops
One park call that knows the waiter's kindJava virtual threads, Go gopark, event-listener, Folly Baton
Task-level primitives onlytokio, Seastar, Trio, kotlinx (CQS)
Blocks the OS threadRust std, glibc, parking_lot, WebKit, Abseil

Milestones ​

YearMilestone
1991MCS queue locks; Concurrent ML's first-class events
2002Linux futexes merged (2.5.7); Drepper's "Futexes Are Tricky" follows in 2004
2003Capriccio: user-level threads over asynchronous I/O
2004Java 5 java.util.concurrent and AbstractQueuedSynchronizer
2012Windows 8 adds WaitOnAddress
2015–2016WebKit's ParkingLot and WTF::Lock; Rust's parking_lot follows
2017glibc 2.25 ships Riegel's 2016 condition variable, which drops requeue
2016macOS 10.12 adds os_unfair_lock
2021Linux 5.16 adds futex_waitv
2022Rust std replaces pthread with futex locks on Linux
2023Linux 6.7: futex2 syscalls and io_uring futex ops; Java 21 virtual threads; CQS at PLDI
2024macOS 14.4 publishes os_sync_wait_on_address; the SRWLOCK shared-mode fix
2025JDK 24 unpins virtual threads in synchronized (JEP 491); combine-and-exchange locks
2026parking_lot drops automatic eventual fairness (unreleased at the time of reading)

Dates are as the deep-dives establish them; the 2002, 2004 and 2012 entries come from the operating systems' documentation, the others from the cited sources.

Suggested reading paths ​

Examples ​

Two runnable programs, compiled and run by ci examples standalone:

  • mutex-throughput.d — throughput, fairness, and futex waits and wakes per acquisition for a three-state futex word, a parking lock with and without a designated waker, a pthread mutex and a spin lock, from one thread to twice the core count.
  • handoff-latency.d — the round trip of handing a turn between two sleeping threads over a futex word, an eventfd and a pthread condition variable.

Sources ​

Every deep-dive cites its source trees pinned to a commit, and its papers by DOI and full text; the PDFs are kept beside the clones, under $REPOS/papers/fine-grained-locking/.