Use lock operations, here is a sample code:
LONGLONG AtomicRead(LONGLONG* p)
{
return InterlockedCompareExchange64(p, 0, 0);
}
This compares the exchange with zero and sets p to zero if it is already zero - this is noop. InterlockedCompareExchange returns the original 64-bit value pointed to by p.
source
share