roadmap BUILT

836. A C library, stage 2: threads

(The title and slug are provisional.)

Stage 2 of §265 (a C library started from relibc): pthread_create, pthread_join, mutexes, condition variables, thread-local storage for more than one thread, and the thread-safe stdio locking relibc already has. It rides on milestone 812 (std::thread::spawn runs real threads in one address space), which PR #1856 rules is to be built.

First consumers

hackbench (827) in its thread mode, iperf3 (828) and the storage benchmark (833), all on PR #1854.

Reuse: relibc's src/pthread/ and src/sync/ (MIT), seeded as stage 1 seeded the headers.

What it builds

relibc's src/pthread/ and src/sync/, seeded as stage 1 seeded the headers, over two platform calls: thread creation (relibc's rlct_clone) and a wait-on-address pair (its futex_wait and futex_wake). Milestone 812 provides that pair, so src/sync/ is kept nearly whole: corrected 2026-10-11 (UTC), since 812 (#1892) built abi::address_space::WAIT and WAKE, an address-keyed futex (notes/address-wait.md). It has no timeout yet, which a timed wait such as pthread_cond_timedwait will meet. TPIDR_EL0, tp and the x86_64 FS base become per-thread state, which is 812's to switch.

Done when

hackbench's thread mode builds unmodified and runs on all three architectures. It is this block's one program. Not schbench, because the C library does not build system_call() and §265 (a C library started from relibc) stands as written (calef, 2026-10-12 UTC, on #2009: "c, and drop schbench"). Milestone 830 (wakeup latency on nife and Linux, from each kernel's own scheduler trace) measures the tails by tracing instead.

What is built

hackbench (rt-tests 2.11, helpers/build-hackbench.sh) runs unmodified in its thread mode on aarch64, riscv64 and x86_64 under QEMU (system_tests/src/user/c_thread_tests.rs, two tests, skipping where the helper was not run). Over pipes, two groups of three senders and three receivers; over its default socketpair(AF_UNIX, SOCK_STREAM), one group of seven and seven, fifteen threads with the main one. Every sender's 100 messages reach every receiver of its group, every thread is joined, and the process ends with every thread reaped. Each test has an attested falsification. SQLite's speedtest1 and ioping still pass on the threaded library.

The library (nifeos/nife:c_library/README.md is the guide, with its BUGS):

The helpers/build-ioping.sh and build-speedtest1.sh fix: each read only the first of the two lines helpers/c-library-cflags.sh prints, so neither got nife's headers. Both now read both.

What this block decided

Each is reversible:

BUGS

Follow-on

Index row

POSIX threads for nife's C library, on milestone 812's threads, so the scheduling benchmarks can run as their authors wrote them.