Repository navigation
Language Specification (A) : Atomic Operations
Benjamin Kowarsch edited this page Aug 16, 2026
·
3 revisions
Built-in module ATOMIC provides type-safe atomic operations. Its provision is optional.
INTERFACE MODULE ATOMIC; (* OPTIONAL *)
(* Atomic Operations *)
TYPE OPERATION =
( SWAP, (* atomic swap *)
CAS, (* atomic compare and swap *)
INC, (* atomic increment *)
DEC ); (* atomic decrement *)
PROCEDURE AVAIL ( op : OPERATION; bitwidth : CARDINAL ) : BOOLEAN;
(* Returns TRUE if the given operation is available for the given bitwidth,
otherwise FALSE. The value of bitwidth must be a compile time expression. *)
PROCEDURE SWAP = ( VAR target : T; newVal : T ) : T;
(* Atomically writes newVal to target and returns the prior value of target.
Both arguments must be of the same type. The return type matches the argument type. *)
PROCEDURE CAS ( VAR target : T; expectedVal, newVal : T ) : T;
(* Atomically compares expectedVal and target. If they match, newVal is written to
target and expectedVal passed in target. Otherwise, the prior value is passed.
All arguments must be of the same type. The return type matches the argument type. *)
PROCEDURE INC ( VAR target : T; increment : T ) : T;
(* Atomically increments target by increment and returns the prior value of target.
Both arguments must be of the same type, which must be a built−in whole number type.
The increment must be larger than zero. The returned type matches the target type. *)
PROCEDURE DEC ( VAR target : T; decrement : T ) : T;
(* Atomically decrements target by decrement and returns the prior value of target.
Both arguments must be of the same type, which must be a built−in whole number type.
The decrement must be larger than zero. The returned type matches the target type. *)
END ATOMIC.Functions of module ATOMIC may not be assigned nor passed as arguments to any procedure, function or macro.
Copyright © 2015-2018 Modula-2 Software Foundation