This is part of the interlocked API introduced by Microsoft, but the atomic operation problem is mentioned in it. Although it should be only for Microsoft operating systems, I think all operating systems should be consistent. For a numeric operation that has the same or lower CPU bits and is aligned with bytes, the value assignment must be completed. After the assignment, the value must be assigned, after the value is obtained, it must be a value assigned to the value, and no median value exists. Therefore, the 32-bit integer may not cause errors if only one thread writes a value and other threads read the value. If multiple threads are used for reading and writing, but if multiple threads only use it as a bool value and are notified by the bool value, they do not care about the corresponding multi-thread. I think there should be no such use. Interlocked variable access
Applications must synchronize access to variables that are shared by multiple threads. Applications must also ensure that operations on these variables are saved med atomically (stored med in their entirety or not at all .)
Simple reads and writes to properly-aligned 32-bit variables are atomic operations. in other words, you will not end up with only one portion of the variable updated; all bits are updated in an atomic fashion. however, access is not guaranteed to be synchronized. if two threads are reading and writing from the same variable, you cannot determine if one thread will perform its read operation before the other performs its write operation.
Simple reads and writes to properly aligned 64-bit variables are atomic on 64-bit windows. reads and writes to 64-bit values are not guaranteed to be atomic on 32-bit windows. reads and writes to variables of other sizes are not guaranteed to be atomic on any platform.