atomics(3erl) | Erlang Module Definition | atomics(3erl) |
atomics - Atomic Functions
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_ref()
Identifies an atomic array returned from new/2.
new(Arity, Opts) -> atomics_ref()
Types:
Create a new array of Arity number of atomics. All atomics in the array are initially set to zero.
Argument Opts is a list of the following possible options:
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.
Atomics are not tied to the current process and are automatically garbage collected when they are no longer referenced.
put(Ref, Ix, Value) -> ok
Types:
Set atomic to Value.
get(Ref, Ix) -> integer()
Types:
Read atomic value.
add(Ref, Ix, Incr) -> ok
Types:
Add Incr to atomic.
add_get(Ref, Ix, Incr) -> integer()
Types:
Atomic addition and return of the result.
sub(Ref, Ix, Decr) -> ok
Types:
Subtract Decr from atomic.
sub_get(Ref, Ix, Decr) -> integer()
Types:
Atomic subtraction and return of the result.
exchange(Ref, Ix, Desired) -> integer()
Types:
Atomically replaces the value of the atomic with Desired and returns the value it held previously.
compare_exchange(Ref, Ix, Expected, Desired) -> ok | integer()
Types:
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.
info(Ref) -> Info
Types:
Return information about an atomic array in a map. The map has the following keys:
erts 13.1.5 | Ericsson AB |