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 bit integers.
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.
Identifies an atomic array returned from
Create a new atomic array of
Argument
Indicate if the elements of the array will be treated
as signed or unsigned integers. Default is
The integer interval for signed atomics are from
Atomics are not tied to the current process and are automatically garbage collected when they are no longer referenced.
Set atomic to
Read atomic value.
Add
Atomic addition and return of the result.
Subtract
Atomic subtraction and return of the result.
Atomically replaces the value of the atomic with
Atomically compares the atomic with
Return information about an atomic array in a map. The map has the following keys:
The number of atomics in the array.
The highest possible value an atomic in this array can hold.
The lowest possible value an atomic in this array can hold.
Approximate memory consumption for the array in bytes.