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
不是有效的参数:实际上,我们可以使用
AtomicExchange
参数调用Int64
吗,并且这对于32位和64位目标是否可以正常工作? 最佳答案
文档不正确,AtomicExchange
可用于64位操作数。许多固有功能记录不正确,这是又一个。
查看包装原子内在函数的TInterlocked
类方法,它会更加清楚。有这种方法:
class function TInterlocked.Exchange(var Target: Int64; Value: Int64): Int64;
begin
Result := AtomicExchange(Target, Value);
end;
这清楚地表明,即使在32位进程中,
AtomicExchange
也完全支持64位值。关于delphi - AtomicExchange是否支持64位参数?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48538192/