I do understand some of the use cases for InterlockedExchange, I'm guessing that there are far more than I can see for now, but I can't understand the compare part. I'm used in ranged compares for values eg case, between etc but I can't see a use case where I would like to set a value only when it is equal to X where X is very specific ee not a range or something different than the new value. Lets simplify things a bit so we can talk on the same think if I was to re-create those two functions using critical sections for example it would go something along the lines of
function InterLockedExchange(var Target: Pointer;Source: Pointer):Pointer;
begin
EnterCriticalSection(myCS);
try
result := target;
target := Source;
finally
LeaveCriticalSection(myCS);
end;
end;
function InterlockedCompareExchange(var Target: Pointer; NewValue: Pointer; Comperand: Pointer):Pointer;
begin
EnterCriticalSection(myCS);
try
Result := target;
if NewValue = Comperand then target := NewValue;
finally
LeaveCriticalSection(myCS);
end;
end;
and that makes no sense to me at all. Any cases I could take a look? For now is categorized as "nice idea no real value".