admin管理员组

文章数量:1122832

I learned some information related to C++ memory_order from , but I found some content that confused me a bit:

Visible side-effects The side-effect A on a scalar M (a write) is visible with respect to value computation > B on M (a read) if both of the following are true:

  1. A happens-before B.
  2. There is no other side effect X to M where A happens-before X and X happens-before B.

This literature mentions visible side effects, meaning that a side effect A can be seen by another thread's read operation B, and one of the conditions for this is that A happens-before B.

For instance, if A is a relaxed order write to an atomic variable M, and B is a relaxed order read from M, it is evident that if the conditions are right, B can certainly read A. So can we say that A happens-before B in this case?

However, in the literature regarding the happens-before relationship, it mainly refers to inter-thread happens-before, which is based on the conditions established by either synchronizes-with or dependency-ordered-before relationships. Clearly, since both the read and write operations are in relaxed order, they do not fall within these two relationship categories.

Yet, visible side effects must satisfy the happens-before relationship, which I find very contradictory.

Is there a problem with my understanding, or is the literature I read not comprehensive enough? Thank you.

I would like to know if there is a problem with my understanding of visible side effects and the happens-before relationship, and where the problem might be.

本文标签: C Visible SideEffect and HappensBefore RelationStack Overflow