The C # specifications in section 5.5 that read and write specific types (namely bool , char , byte , sbyte , short , ushort , uint , int , float and reference types) are guaranteed to be atomic.
This aroused my interest. How can you do this? I mean that my modest personal experience showed me only the blocking of variables or the use of barriers if I want to read and write in order to look atomic; this will be a performance killer if you need to do this for each individual read / write. And yet C # does something with a similar effect.
Perhaps other languages ββ(like Java) do this. I seriously donβt know. My question is not really for the language, but I know that C # does this.
I understand that it may deal with certain specific processor instructions and may not be used in C / C ++. However, I would still like to know how this works.
[EDIT] Honestly, I thought that reading and writing could be non-atomic under certain conditions, for example, a processor can access a memory location when another processor writes there. Does this happen only when the processor cannot simultaneously process the entire object, for example, because it is too large or because the memory is not aligned on the corresponding boundary?
c # atomic
zneak
source share