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
?
sizeof(bool)
. – Transferencestd::atomic<bool>
with at leastmemory_order_relaxed
, not necessarily the defaultmo_seq_cst
, to get safe asm. – Kurr