notes

Address wait and wake

Name: provisional, minted 2026-11-21 (UTC) by lane futex-spelled-out.

Written 2026-10-10 (UTC) by milestone 812 (std::thread::spawn runs real threads in one address space)'s lane. The ruling is §269 (how threads share a process) fork 2; the wire contract is moho_abi::address_space::WAIT and WAKE, and the flags are moho_abi::address_wait.

What it is for

std's locks on Linux, the BSDs, Fuchsia and WASI are built on one primitive: park this thread on a word if the word still holds what I saw, and wake up to n threads parked on a word. Mutex::new is const and makes no system call, so the kernel cannot know a lock exists until the first time it is contended. An address wait (Linux calls it a fast user-space mutex, "futex") needs no object, which is why §269 chose it over a capability per lock.

The contract, in short

WAIT(va, flags, expected) WAKE(va, flags, count)
returns 0 woken, 1 the word differed how many were woken
flags PRIVATE with WIDTH_32_BITS, nothing else (futex2's bit layout) same
the capability the caller's own space, with READ same
va 4-aligned, user half, mapped readable 4-aligned, user half; need not be mapped

Refusals come in a fixed order: BadMethod (a form §269 reserves: shared, or another size), then NotPermitted, BadPointer, WrongObject. WAIT returns Gone if the thread's region is destroyed under it.

Why it is correct

The kernel reads the word and parks the thread under one hold of IPC_TABLES, and WAKE takes the same lock. A waker stores the new value and then wakes. If the store lands before the waiter's hold, the lock's release and acquire order it before the waiter's read, and the waiter returns 1 without sleeping. If it lands after, the waiter is already parked when WAKE looks. The kernel's load is Acquire, so whatever the waker wrote before its store is visible to the thread once it returns.

The queues are crates/inter_process_communication/src/address_wait.rs: 64 buckets of intrusive FIFOs, keyed by (space name, address). A wake takes waiters oldest first and leaves the others in their order. A thread torn down while parked is unlinked by sched::finish_blocked_resident.

How it is proved

system_tests/src/user/address_wait_tests.rs, on all three architectures, with a hand-written waiter per ISA:

The first two have replayable falsifications. The host tests in the crate cover key collision, order, max, and removal.

BUGS