Are reads and writes atomic?
> Suppose an integer variable is shared between threads. Is it safe to > assume that reads and writes are atomic (assuming reads and writes are > single instructions)? How big is an int? Does the machine provide instructions to read and write data with that size atomically? Does the compiler always generate the appropriate instructions to read and write ‘int’ data atomically? (E.g., “load 32-bit” rather than ‘load 64-bit’ the enclosing 64-bit cell and mask/shift.) Does the compiler/linker always ALIGN data of that size “naturally”? (If not) Does the machine still read and write data of that size atomically when the alignment is not natural? > I suspect the answer is ‘no, no standard provide such a guarantee’, > but then I’d like to know on what, if any, kind of hardware I can > expect it to fail. You’re trying to rely on a bunch of different guarantees from the hardware up through the compiler and linker. You won’t find ALL of these guarantees in any single document. The C and C++ lang