Say we have two threads, one is reading a bool in a loop and another can toggle it at certain times. Personally I think this should be atomic because sizeof(bool) in C++ is 1 byte and you don’t read/write bytes partially but I want to be 100% sure.
So yes or no?
EDIT:
Also for future reference, does the same apply to int?
It all depends on what you actually mean by the word “atomic”.
Do you mean “the final value will be updated in one go” (yes, on x86 that’s definitely guaranteed for a byte value – and any correctly aligned value up to 64 bits at least), or “if I set this to true (or false), no other thread will read a different value after I’ve set it” (that’s not quite such a certainty – you need a “lock” prefix to guarantee that).