AtomicExchange是否支持64位参数?

时间:2018-01-31 09:00:43

标签: delphi

documentation for AtomicExchange将方法签名赋予:

function AtomicExchange(var Target; Value: <Integer or NativeInt or Pointer>): Integer; overload;
function AtomicExchange(var Target; Value: <Integer or NativeInt or Pointer>): Int64; overload;
function AtomicExchange(var Target; Value: <Integer or NativeInt or Pointer>): Pointer; overload;
function AtomicExchange(var Target; Value: <Integer or NativeInt or Pointer>): NativeInt; overload;

但在实践中,似乎Int64也是一个有效的参数,如:

function AtomicExchange(var Target; Value: <Integer or Int64 or NativeInt or Pointer>): Integer; overload;
function AtomicExchange(var Target; Value: <Integer or Int64 or NativeInt or Pointer>): Int64; overload;
function AtomicExchange(var Target; Value: <Integer or Int64 or NativeInt or Pointer>): Pointer; overload;
function AtomicExchange(var Target; Value: <Integer or Int64 or NativeInt or Pointer>): NativeInt; overload;

注意:除文档外,IDE工具提示还建议Int64不是有效参数:

enter image description here

事实上,我们可以使用AtomicExchange参数调用Int64,这是否可以正常用于32位和64位目标?

1 个答案:

答案 0 :(得分:5)

文档不正确,AtomicExchange可用于64位操作数。许多内在函数都记录不正确,这是另一个。

查看包含原子内部函数的TInterlocked类方法,它更加清晰。有这种方法:

class function TInterlocked.Exchange(var Target: Int64; Value: Int64): Int64;
begin
  Result := AtomicExchange(Target, Value);
end;

这清楚地表明AtomicExchange完全支持64位值,即使在32位进程中也是如此。