atomics(3erl)
π¦ NAME π¦
atomics β Atomic Functions. Bestie, this is the Erlang Module Definition page for atomics, and it's literally all about doing atomic operations towards mutable atomic variables. π
β¨ DESCRIPTION β¨
Okay so this module provides a set of functions to do atomic operations towards mutable atomic variables. The implementation utilizes only atomic hardware instructions without any software level locking, which makes it very efficient for concurrent access. The atomics are organized into arrays with the following semantics:
- Atomics are
64 bitintegers. - Atomics can be represented as either signed or unsigned.
- Atomics wrap around at overflow and underflow operations.
- All operations guarantee atomicity. No intermediate results can be seen. The result of one mutation can only be the input to one following mutation.
- All atomic operations are mutually ordered. If atomic B is updated after atomic A, then that is how it will appear to any concurrent readers. No one can read the new value of B and then read the old value of A.
- Indexes into atomic arrays are one-based. An atomic array of arity N contains N atomics with index from 1 to N.
π DATA TYPES π
atomics_ref()
Identifies an atomic array returned from new/2. iykyk π«Ά
π₯ EXPORTS π₯
new(Arity, Opts) -> atomics_ref()
Types:
Arity = integer() >= 1
Opts = [Opt]
Opt = {signed, boolean()}
Create a new array of Arity number of atomics. All atomics in the array are initially set to zero. fresh start energy β¨
Argument Opts is a list of the following possible options:
{signed, boolean()}β Indicate if the elements of the array will be treated as signed or unsigned integers. Default istrue(signed).
The integer interval for signed atomics are from -(1 bsl 63) to (1 bsl 63)-1 and for unsigned atomics from 0 to (1 bsl 64)-1. math but make it fashion π
Atomics are not tied to the current process and are automatically garbage collected when they are no longer referenced. self-care for memory π
put(Ref, Ix, Value) -> ok
Types:
Ref = atomics_ref()
Ix = Value = integer()
Set atomic to Value. boom, updated π₯
get(Ref, Ix) -> integer()
Types:
Ref = atomics_ref()
Ix = integer()
Read atomic value. just vibes and a peek π
add(Ref, Ix, Incr) -> ok
Types:
Ref = atomics_ref()
Ix = Incr = integer()
Add Incr to atomic. math slay π
add_get(Ref, Ix, Incr) -> integer()
Types:
Ref = atomics_ref()
Ix = Incr = integer()
Atomic addition and return of the result. add and tell me what happened β¨
sub(Ref, Ix, Decr) -> ok
Types:
Ref = atomics_ref()
Ix = Decr = integer()
Subtract Decr from atomic. minus minus, bestie π
sub_get(Ref, Ix, Decr) -> integer()
Types:
Ref = atomics_ref()
Ix = Decr = integer()
Atomic subtraction and return of the result. take away and report back π¦
exchange(Ref, Ix, Desired) -> integer()
Types:
Ref = atomics_ref()
Ix = Desired = integer()
Atomically replaces the value of the atomic with Desired and returns the value it held previously. out with the old, in with the new π
compare_exchange(Ref, Ix, Expected, Desired) -> ok | integer()
Types:
Ref = atomics_ref()
Ix = Expected = Desired = integer()
Atomically compares the atomic with Expected, and if those are equal, set atomic to Desired. Returns ok if Desired was written. Returns the actual atomic value if not equal to Expected. the ultimate vibe check π
info(Ref) -> Info
Types:
Ref = atomics_ref()
Info =
#{size := Size, max := Max, min := Min, memory := Memory}
Size = integer() >= 0
Max = Min = integer()
Memory = integer() >= 0
Return information about an atomic array in a map. The map has the following keys:
size: The number of atomics in the array.max: The highest possible value an atomic in this array can hold.min: The lowest possible value an atomic in this array can hold.memory: Approximate memory consumption for the array in bytes.
receipts, stats, and a whole map of details π§
Made with π by Ericsson AB Β· erts 13.2.2.5 Β· atomics(3erl). Date? The footer doesn't give one, so no cap, we're not inventing it bestie π΅οΈ π«Ά
π¦ where this page comes from
- ubuntu noble: erlang-manpages 1:25.3.2.8+dfsg-1ubuntu4 Β· Apache-2.0
- ubuntu noble: erlang-manpages 1:25.3.2.8+dfsg-1ubuntu4.8 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms