Following the example of this Dr Dobbs article , the simple assignment of atomic variables in C11 is atomic .
Standard C11 (ISO / IEC 9899: 2011), section 6.2.6.1/9, states:
Loads and storages of objects with atomic types are performed using memory_order_seq_cst semantics.
In addition to atomic, operations performed with memory_order_seq_cst semantics have the same order observed by all threads (aka sequential sequential ordering ).
Without a classifier like _Atomic it is possible that the assignment will be non-atomic. Assigning a 64-bit value (for example, a long long ) on a 32-bit machine requires two CPU cycles. If another thread reads the value between the two loops, they will receive 4 bytes of the old value and 4 bytes of the new value.
source share