In a word, no.
You can use something like InterlockedIncrement()
depending on your platform. On .NET you can use the Interlocked
class methods (Interlocked.Increment()
for example).
A Rob Kennedy mentioned, even if the operation is implemented in terms of a single INC
instruction, as far as the memory is concerned a read/increment/write set of steps is performed. There is the opportunity on a multi-processor system for corruption.
There's also the volatile
issue, which would be a necessary part of making the operation thread-safe - however, marking the variable volatile
is not sufficient to make it thread-safe. Use the interlocked support the platform provides.
This is true in general, and on x86/x64 platforms certainly.