Atomic read / write size on 64-bit systems for .NET?

The C # specification says that reading and writing are atomic for 32-bit types and less (and also for references). Therefore, if I have an Int32 field in my class, I know that several threads can read and write to it, and they will be atomic in operation, and therefore the value will always be consistent (although caching problems are a potential problem, but this is not a problem of this question).

Is it the same on 64-bit systems? If I compile my application for 64-bit, does that mean that Int64 is still considered non-atomic? Or now I can consider Int64 atomic in read / write, because it is compiled and works on a 64-bit system?

+6
source share
1 answer

It should be the same (not atomic) - the values ​​must be correctly aligned so that 64-bit values ​​have atomic read / write, but as far as I know, for CLR it is not necessary to always align the Int64 values ​​that are the way to go.

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

+3
source

Source: https://habr.com/ru/post/899652/


All Articles