Memory-order markers and fixed-width integer atomic operations over one referenced integer object.
Memory orders
ACQUIRE: acquire-order marker.
RELEASE: release-order marker.
Examples
"atomic" use
"control" use
{} () {} [
ACQUIRE printStack _:;
RELEASE printStack _:;
] "main" exportFunction
Expected Output During Compilation
{
MEMORY_ORDER: ();
ORDER: "acquire" virtual;
}
{
MEMORY_ORDER: ();
ORDER: "release" virtual;
}
Supported schemas
- Accepted schemas are
Int8, Int16, Int32, Int64, Nat8, Nat16, Nat32, and Nat64.
Intx and Natx are not supported.
- Each operation requires the referenced object and the written value, if present, to use the same supported fixed-width integer schema.
Operation summary
atomicLoad accepts only ACQUIRE.
atomicStore accepts only RELEASE.
atomicExchange, atomicOr, and atomicXor accept ACQUIRE and RELEASE.
Nat operations preserve the same schema in results.
Int schemas are accepted, but atomicLoad, atomicExchange, atomicOr, and atomicXor return the corresponding same-width Nat schema.
atomicExchange (value ref order -- previousValue)
Atomically stores value and returns the previous value.
value and ref must use the same supported fixed-width integer schema.
Nat inputs return the previous value with the same schema.
Int inputs return the previous value with the corresponding same-width Nat schema.
order must be ACQUIRE or RELEASE.
atomicLoad (ref order -- value)
Atomically loads the current value from ref.
ref must use one supported fixed-width integer schema.
Nat inputs return the same schema.
Int inputs return the corresponding same-width Nat schema.
order must be ACQUIRE.
atomicOr (value ref order -- previousValue)
Atomically applies bitwise OR with value and returns the previous value.
value and ref must use the same supported fixed-width integer schema.
Nat inputs return the previous value with the same schema.
Int inputs return the previous value with the corresponding same-width Nat schema.
order must be ACQUIRE or RELEASE.
atomicStore (value ref order --)
Atomically stores value into ref.
value and ref must use the same supported fixed-width integer schema.
order must be RELEASE.
atomicXor (value ref order -- previousValue)
Atomically applies bitwise XOR with value and returns the previous value.
value and ref must use the same supported fixed-width integer schema.
Nat inputs return the previous value with the same schema.
Int inputs return the previous value with the corresponding same-width Nat schema.
order must be ACQUIRE or RELEASE.
See also
- windows/Mutex: SRW lock wrapper with exclusive and shared locking.
- Spinlock: Lightweight spinlock for concurrency control.
- lockGuard: Scope-based locking and unlocking helpers.