System.AtomicCmpExchange

From Appmethod Libraries
Jump to: navigation, search

Object Pascal

function AtomicCmpExchange(var Target; NewValue: <Integer or NativeInt or Pointer>; Comparand: <Integer or NativeInt or Pointer>; [out Succeeded: Boolean]): Integer; overload;
function AtomicCmpExchange(var Target; NewValue: <Integer or NativeInt or Pointer>; Comparand: <Integer or NativeInt or Pointer>; [out Succeeded: Boolean]): Int64; overload;
function AtomicCmpExchange(var Target; NewValue: <Integer or NativeInt or Pointer>; Comparand: <Integer or NativeInt or Pointer>; [out Succeeded: Boolean]): Pointer; overload;
function AtomicCmpExchange(var Target; NewValue: <Integer or NativeInt or Pointer>; Comparand: <Integer or NativeInt or Pointer>; [out Succeeded: Boolean]): NativeInt; overload;
function AtomicCmpExchange(var Target; NewValue: <Integer or NativeInt or Pointer>; Comparand: <Integer or NativeInt or Pointer>; [out Succeeded: Boolean]): Integer; overload;
function AtomicCmpExchange(var Target; NewValue: <Integer or NativeInt or Pointer>; Comparand: <Integer or NativeInt or Pointer>; [out Succeeded: Boolean]): Int64; overload;
function AtomicCmpExchange(var Target; NewValue: <Integer or NativeInt or Pointer>; Comparand: <Integer or NativeInt or Pointer>; [out Succeeded: Boolean]): Pointer; overload;
function AtomicCmpExchange(var Target; NewValue: <Integer or NativeInt or Pointer>; Comparand: <Integer or NativeInt or Pointer>; [out Succeeded: Boolean]): NativeInt; overload;

Properties

Type Visibility Source Unit Parent
function public System.pas System System

Description

Atomic intrinsic Compare and Exchange function for use with Object Pascal mobile compilers. Compares the contents of the <Target> to a given value (<Comparand>) and, only if they are the same, modifies the contents of <Target> to the new value.

This function always returns the original value of <Target>. If a <Succeeded> parameter is provided, <Succeeded> becomes True if there is a value exchange (even if both <Target> and <NewValue> are the same); it becomes False otherwise.

Because the Object Pascal mobile compilers do not support a built-in assembler, the System unit provides four atomic intrinsic functions that provide a way to atomically exchange, compare and exchange, increment, and decrement memory values.

AtomicCmpExchange is used for comparing and exchanging memory values.

Atomic operations are used to:

  • Implement multi-threaded locking primitives
  • Provide the primitives necessary for implementing so-called "lock-free" structures

See Also