6.100. kink/thread/ATOMIC

6.100.1. type atomic

`atomic` is a reference to a value. `atomic` supports read and write actions ordered by the synchronization order, and atomic compare-and-set action.

6.100.1.1. Atomic.load

`load` gets the value which `Atomic` references as a synchronization action, and returns the value.

6.100.1.2. Atomic <- New

`<-` operator, or `op_store` method, writes `New` as the referenced value of `Atomic`. The write operations is done as a synchronization action.

6.100.1.3. Atomic.compare_and_set(Expected New)

`compare_and_set` performs an atomic compare-and-set operation on `Atomic`. If `New` is written, `compare_and_set` returns true. If `New` is not written, `compare_and_set` returns false.

`compare_and_set` reads the referenced value with the memory semantics of `load`. If the read value is same as `Expected`, `compare_and_set` writes `New` as the referenced value of`Atomic`, with the memory semantics of `<-` operator. If the read value is not same as `Expected`, `compare_and_set` returns false.

6.100.1.4. Atomic.update($compute_new)

`update` is a convenient method to atomically update the referenced value of `Atomic`, with a value computed from the current value.

𝄋 `update` reads the current value, called `Old`, with the memory semantics of `load`. Then `update` calls compute_new(Old) to get a value `New`. After that, `update` performs compare-and-set operation with `Old` as the expected current value, and `New` as the new value. If `New` is written, `update` returns a `vec` [Old New]. If `New` is not written, `update` restarts from 𝄋.

Precondition

$compute_new must be a fun which takes an arg.

6.100.2. ATOMIC.new(Initial_val)

`new` returns a new `atomic` which references `Initial_val`.

6.100.3. ATOMIC.is?(Val)

`is?` returns whether `Val` is an `atomic`.