LIBATOMIC-OPS(3)
β¨ NAME β¨
libatomic-ops β bestie, it's literally a library that hands you user level atomic operations π
πΈ SYNOPSIS πΈ
#include <atomic_ops.h>
cc ... -latomic_ops
okay so real talk: all of these operations have an extra barrier option that you can set explicitly, so keep that in mind π«Ά
void AO_load(AO_t *addr)
void AO_store(AO_t *addr, AO_t val)
int AO_test_and_set (AO_t *addr)
AO_t AO_fetch_and_add(AO_t *addr, AO_t incr)
AO_t AO_fetch_and_add1(AO_t *addr)
AO_t AO_fetch_and_sub1(AO_t *addr)
void AO_or(AO_t *p, AO_t incr)
int AO_compare_and_swap(AO_t *addr, AO_t old, AO_t new_val)
π¦ DESCRIPTION π¦
libatomic-ops is your programming interface to a comprehensive range of atomic operations at user level. no cap, it's a whole buffet π₯
We define various atomic operations on memory in a machine-specific way. And unfortunately β as is tradition π β this gets complicated, because these might or might not be combined with various memory barriers. So the actual operations we define have the form AO_<atomic-op>_<barrier> for all plausible combinations of <atomic-op> and <barrier>. it's giving β¨combinatoricsβ¨
π the valid barrier suffixes π
_releaseβ earlier operations may not be delayed past it._acquireβ later operations may not move ahead of it._readβ subsequent reads must follow this operation and preceding reads._writeβ earlier writes precede both this operation and later writes._fullβ ordered with respect to both earlier and later memops._release_writeβ ordered with respect to earlier writes._acquire_readβ ordered with respect to later reads.
This of course results in a mild combinatorial explosion π
The library will find the least expensive way to implement your operations on the applicable hardware. In many cases that will involve, for example, a stronger memory barrier, or a combination of hardware primitives. she's efficient, she's resourceful, she's the moment π
β οΈ real talk, do NOT skip this part: atomicity guarantees are valid only if both readers and writers useAO_operations to access the shared value, while ordering constraints are intended to apply to all memory operations. If a location can potentially be accessed simultaneously from multiple threads, and one of those accesses may be a write access, then all such accesses to that location should be throughAO_primitives. However ifAO_operations enforce sufficient ordering to ensure that a locationxcannot be accessed concurrently, or can only be read concurrently, thenxcan be accessed via ordinary references and assignments. π«Ά
All operations operate on an AO_t value, which is the natural word size for the architecture. slay π
AO_loadandAO_storeβ load and store the specified pointer address.AO_test_and_setβ atomically replaces an address withAO_TS_SETand returns the prior value. AnAO_TS_tlocation can be reset with theAO_CLEARmacro, which usually usesAO_store_releaseπAO_fetch_and_addβ takes an address and a value to add.AO_fetch_and_add1andAO_fetch_and_sub1β provided since they may have faster implementations on some hardware ποΈAO_orβ atomically ors anAO_tvalue into a memory location, but does not provide access to the original. no receipts, sorry bestie πAO_compare_and_swapβ takes an address, an old value and a new value and returns anint. non-zero indicates the compare and swap succeeded β¨
π SEE ALSO π
libatomic-stack(3), libatomic-malloc(3)
π AUTHOR π
This manual page was written by Ian Wienand <ianw@gelato.unsw.edu.au>, based on comments in the source code. It was written for the Debian project (but may be used by others). icon behavior, fr fr π
okay that's the whole page bestie, and here's the lil sign-off π this one's from Ian Wienand, dated May 17, 2005, and it lives in the LIBATOMIC-OPS(3) section of the manual. go forth and be atomic π¦β¨
π¦ where this page comes from
- debian bookworm: libatomic-ops-dev 7.6.14-1
- debian trixie: libatomic-ops-dev 7.8.2-1
- ubuntu jammy: libatomic-ops-dev 7.6.12-1
- ubuntu noble: libatomic-ops-dev 7.8.2-1build1
- ubuntu questing: libatomic-ops-dev 7.8.2-1build1
- ubuntu resolute: libatomic-ops-dev 7.10.0-1
- ubuntu stonking: libatomic-ops-dev 7.10.0-1
- Copyright 2005 Ian Wienand, Gelato@UNSW
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms