Catalog of Atomic Operations in UNIX/POSIX Systems for Thread-Safe Programming
By
onurkanbkrc
If you only eat one bagel today, this is the bagel.
Summary
This article presents a catalog of atomic operations available in UNIX-like/POSIX-compliant operating systems that can be used as building blocks for creating thread-safe and multi-process-safe programs without requiring mutexes or read/write locks. The author advocates for leveraging kernel-level atomic operations rather than implementing custom locking mechanisms, arguing that kernel developers are more trustworthy and that it's inefficient to lock around operations that are already atomic at the kernel level. The catalog is presented as a living document expected to be updated frequently.
Key quotes
· 4 pulledThis is a catalog of things UNIX-like/POSIX-compliant operating systems can do atomically, making them useful as building blocks for thread-safe and multi-process-safe programs without mutexes or read/write locks.
The philosophy here is to let the kernel do as much work as possible. At my most pessimistic, I trust the kernel developers more than I trust myself.
More practically, it's stupid to spend CPU time locking around an operation that's already atomic at the kernel level.
The list is by no means exhaustive and I expect it to be updated frequently for the foreseeable future.
You might also wanna read
Restartable Sequences: A Linux Kernel Feature for Lock-Free Thread-Safe Programming
This article explores restartable sequences (rseq), a Linux kernel feature introduced in version 4.18 (circa 2018) that enables creation of
Zig Days: Collaborative Full-Day Programming Events for the Zig Community
Zig Days are full-day collaborative programming events organized by the Zig community, typically held on Saturdays. Participants meet in the
Spectre Programming Language Documentation: A Contract-Based Approach to Safe Low-Level Systems Programming
Spectre is a contract-based programming language designed for safe low-level systems programming. It enforces correctness through type-level
A Grounded Conceptual Model for Ownership Types in Rust Programming
This article presents a grounded conceptual model for ownership types in Rust, the programming language known for memory safety without garb
Rail: A Self-Hosting Systems Programming Language with Pure-Rail TLS 1.3 Implementation
Rail is a self-hosting systems programming language that compiles itself without any C dependencies. The compiler is written in Rail and pro
Solod: A Go Subset That Compiles to C for Systems Programming
Solod is a strict subset of the Go programming language that compiles to regular C code, designed for systems programming with manual memory
