JCL Help:LockedCompareExchange@Int64@Int64@Int64

From Project JEDI Wiki
Jump to navigationJump to search


Summary

Thread safe compare and exchange.


Pascal

 function LockedCompareExchange(var Target: Integer; Exch: Integer; Comp: Integer): Integer; overload;
function LockedCompareExchange(var Target: TObject; Exch: TObject; Comp: TObject): TObject; overload;
function LockedCompareExchange(var Target: Pointer; Exch: Pointer; Comp: Pointer): Pointer; overload;
function LockedCompareExchange(var Target: Int64; Exch: Int64; Comp: Int64): Int64; overload;


Parameters

Parameters Description
var Target: Integer The target variable to compare Value and which conditionally receives the value of Exch.
Exch: Integer The value which is moved into Target if Comp and Target are equal.
Comp: Integer The comperand which Target is compared against.


Return Value

The value of Target on procedure entry. Depending on the comparison, Target may have been updated or have retained its value.


Description

LockedCompareExchange compares Comp with Target. If they are equal the value of Exch is moved into Target, otherwise Target retains its value. All this is performed in a locked, thread-safe manner. The LockedXxx functions allow for a simple and efficient way for applications to synchronize access to and manipulate integer variables which are shared by multiple threads.


See Also

LockedExchangeSub LockedExchange LockedExchangeInc LockedExchangeDec


About

Unit

JclSynch


Donator

Azret Botash


Notes

The Win32 API provides similar functions. Look up InterlockedXxx in the Platform SDK.


Contribute to this help topic

This documentation wiki is based on the collaborative effort of Project JEDI users. Your edits are welcome in order to improve documentation quality: edit this page