7

The C# Specification says that reading and writing is atomic for 32bit types and smaller (as well as for references). So if I have an Int32 field in my class I know that multiple threads can read and write to it and they will be atomic in operation and so the value will always be consistent (although caching issues are a potential problem but that is not the point of this question).

Is this the same on 64bit systems as well? If I compile my app for 64bit does that mean an Int64 is still considered to not be atomic? Or can I now consider an Int64 to be atomic in read/write because it is compiled for and running on a 64bit system?

Phil Wright
  • 22,580
  • 14
  • 83
  • 137

1 Answers1

3

It should be the same (not atomic) - values must be aligned properly to allow 64 bit values to have atomic read/write, but as far as I know there is no requirement for CLR to always align Int64 values that way.

Check out How to guarantee 64-bit writes are atomic? for some discussion on it.

Community
  • 1
  • 1
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179