Data dependencies with std::memory_order_consume
std::memory_order_consume deals with data dependencies on atomics; these data dependencies exist in two ways. First, let us look at carries-a-dependency-to in a thread and dependency-ordered before between two threads. Both dependencies introduce a happens-before relation. These are the kind of relations we are looking for. What does carries-a-dependency-to and dependency-order-before mean?
- carries-a-dependency-to: If the result of operation A is used as an operand in operation B, then A carries-a-dependency-to B.
- dependency-ordered-before: A store operation (with std::memory_order_release, std::memory_order_acq_rel or std::memory_order_seq_cst) is dependency-ordered-before load operation B (with std::memory_order_consume) if the result of load operation B is used in a further operation C in the same thread. It is important to note that operations B and C have to be in the same thread.
I know from personal experience that both definitions might not be easy to digest. Here is a graphic to visualize them.