Restartable Sequences Enable Lock-Free Threading on Multi-Core
Original: Restartable Sequences
Why This Matters
Revolutionary approach to multi-core programming enables massive performance gains as processor core counts increase.
Linux rseq feature allows creation of thread-safe data structures without locks or atomics, showing 34x-43x performance improvements on high-core systems. Currently limited to Linux assembly code, but expected to expand across platforms.
Restartable sequences (rseq), introduced in Linux 4.18, enable lock-free thread-safe programming by leveraging kernel cooperation. The system allocates 32 bytes of TLS memory per thread, tracking CPU numbers and allowing threads to specify assembly instruction sequences. When kernel preempts threads during these sequences, it redirects execution to abort handlers for retry operations. Performance testing shows dramatic improvements: 3x faster on Raspberry Pi 5, 34x on 128-core Ampere Altra, and 43x on 96-core AMD Threadripper Pro. Currently used only by tcmalloc, jemalloc, glibc, and cosmopolitan libraries. The technology addresses scalability challenges as processors reach 128-192 cores, replacing traditional mutex-based approaches with more efficient alternatives.