Am I right with my understanding?
No. You misunderstand memory orders.
suppose T2 (load) executes 123ns later than T1 (store) ...
In this case, T2 will see what T1 does with any type of memory order (moreover, this property is used to read / write any memory area, see, for example, http://www.open-std.org/jtc1/sc22/ wg21 / docs / papers / 2015 / n4431.pdf , 1.10, p. 15). The key word in your phrase is later : it means that someone else forces you to organize these operations.
Memory orders are used for another scenario:
It allows you to perform some operation OP1 in the stream T1 before the storage operation, after which OP2 appears, OP3 enters the stream T2 before loading, OP4 appears after it.
Suppose that some order between var.store() and var.load() can be observed by threads. What can be guaranteed about cross-threading settings for other operations ?
- If
var.store uses memory_order_release , var.load uses memory_order_acquire and var.store ordered to var.load (i.e. loading returns 2), then the effect of OP1 ordered to OP4 .
For example, if OP1 writes some variable var1, OP4 reads this variable, then you can be sure that OP4 will read what OP1 writes before. This is the most used case.
- If both
var.store and var.load use memory_order_seq_cst and var.store ordered after var.load (i.e. load returns 0, which was the value of the variable before the repository), then the effect of OP2 ordered after OP3 .
This memory order is required for some complex synchronization schemes.
- If either
var.store or var.load uses memory_order_relaxed , then with any order var.store and var.load you can guarantee that there is no order of operations with transverse streams.
This memory order is used in case someone else provides the order of operations. For example, if the creation of the T2 stream occurs after var.store in T1 , then OP3 and OP4 ordered after OP1 .
UPDATE : 123 ns later implies *someone else* force ordering , because the computer processor has no idea about universal time, and no operation has an exact moment when it is executed. To measure the time between two operations, you must:
- Observe the order between the completion of the first operation and the beginning of the countdown on some processor.
- Observe the order between the beginning and the end of the counter.
- Observe the order between the start of the end time and the start of the second operation.
Transitively, these steps make order between the first and second.