U
user8583
I am trying to understand if/why sharing a simple 'int' variable is unsafe in a multithreading context, under the assumption that only one thread writes on it, and the other threads only read it.
I understand that without further constrains the fact that other threads only read the int is a matter of blind confidence in the programmer. I also understand that there are atomic templates or interlocked operations that are widespread and easy to use. But nonetheless I would like to know if thereis something more fundamental about the unsafety of a shared 'int' that I quite don't get in this particular situation where only one thread is expected to modify the data.
I understand that without further constrains the fact that other threads only read the int is a matter of blind confidence in the programmer. I also understand that there are atomic templates or interlocked operations that are widespread and easy to use. But nonetheless I would like to know if thereis something more fundamental about the unsafety of a shared 'int' that I quite don't get in this particular situation where only one thread is expected to modify the data.