I have a pointer (IntPtr
) to some location in the process virtual memory, I need to be able to write a 32-bit integer into this location atomically, as there can be several native threads that read/write the integer from/to this location. Currently I'm using Marshal.WriteInt32
to do so, but I'm not sure if this function writes memory atomically.
So far I haven't run into race condition situation during test, but I want to know for sure. Are all Marshal.WriteInt*
functions write memory atomically? If not, how can I do it?