In my application several threads increment some counter and only one reads this value (main thread). As far I know, reading 32-bit value is thread-safe if it is aligned by double word, so I use such code:
TMyStat = class
property Counter: Integer read FCounter;
But I'm not sure that it's safe to mix
Interlocked functions and direct access to value.
Should I use
function TMyStat.GetCounter: Integer;
Result := InterlockedCompareExchange(FCounter, 0, 0);