AtomicExchange 需要一个 Integer 或 NativeInt 变量。那么我应该如何以线程安全的方式设置记录的值呢?
有问题的记录原则上看起来像这样(它实际上也有更多的便利功能和属性):
TStatusCode = record
private
FValue: Cardinal;
public
constructor Create(AValue: Cardinal);
class operator Equal(Left, Right : TStatusCode): Boolean;
class operator Implicit(Value: TStatusCode): Cardinal;
class operator Implicit(Value: Cardinal): TStatusCode;
class operator NotEqual(Left, Right : TStatusCode): Boolean;
property Value: Cardinal read FValue;
end;