Reading an aligned 32-bit value is atomic (i.e. all 32 bits are guaranteed to be consistent). But the read is not synchronized. You may not read the "current" value; but instead a value from the caches.
FCounter := 1; //number of threads running
FResult := 0; //the answer to everything
And then your thread:
FResult := 42; //set the answer before we indicate we're done
And then your code checks that the thread is done:
if (FCounter <= 0) then
//Thread is done; read the answer
ShowMessage('The answer is: '+IntToStr(FResult));
The answer is: 0
Even though your flag said the thread set the result, you read the result value out of your local cache.
- Even though the read of
FResult is atomic
- they aren't synchronized
If you are only using
FCounter then you are fine. But as soon as you use anything else and expect them to be consistent, then you need to also use something to enforce synchronization.
The strict answer to your question is that reading a 32-bit aligned value is already an atomic operation.
But it's entirely possible that people coming here to read this question might forget that the read being atomic is a small part of your worries.