3.57. kink/thread/ATOMIC

Provides atomic operations including compare-and-set.

3.57.1. ATOMIC.atomic?(Val)

Returns whether the Val is an atomic reference.

3.57.2. ATOMIC.new(Initial_val)

Makes a new atomic with Initial_val as the initial val.

3.57.3. Type atomic

An atomic reference.


Returns the val of the Atomic reference.


Sets New_val as the new val of the Atomic reference.

Atomic.compare_and_set(Expected Next)

Atomically sets the Next val to the Atomic reference, only if the current val is identical to Expected.

Returns whether the val could be set.


Atomically updates the val of the Atomic reference, and returns a pair of [Old New], where Old is the val just before the update, and New is the val just after the update.

The New val is computed by compute_next(Old), where Old is the current val of the Atomic reference. $compute_next may be invoked multiple times, thus it must not have side-effect.