The following is a quote from C++ Standard - Memory Order:
If an atomic store in thread A is tagged memory_order_release and an atomic load in thread B from the same variable is tagged memory_order_acquire, all memory writes (non-atomic and relaxed atomic) that happened-before the atomic store from the point of view of thread A, become visible side-effects in thread B. That is, once the atomic load is completed, thread B is guaranteed to see everything thread A wrote to memory.
The synchronization is established only between the threads releasing and acquiring the same atomic variable. Other threads can see different order of memory accesses than either or both of the synchronized threads.
Consider an atomic variable v
and the following steps:
- Thread
A
stores inv
usingmemory_order_release
- Thread
B
stores inv
usingmemory_order_release
- Thread
C
loads fromv
usingmemory_order_acquire
Is the following statement true: "thread C
is guaranteed to see everything thread A
or B
wrote to memory."
Aucun commentaire:
Enregistrer un commentaire