Does the C++11 memory model allow hoisting relaxed atomic loads out of loops?

六眼飞鱼酱① 提交于 2019-12-01 15:30:06

Forget about relaxed, there's no guarantee that an atomic store ever become visible to an atomic load in a different thread. The best you get is the normative encouragement in [atomics.order]/12 (and analogous wording in [intro.progress]/18):

Implementations should make atomic stores visible to atomic loads within a reasonable amount of time.

...which is not a requirement.

(C11 has identical wording in §7.11.3/16)

Since hoisting the load leads to behavior indistinguishable from a non-hoisted load where the store never becomes visible, and since the latter is conforming, an implementation is allowed by the as-if rule to hoist the load regardless of the memory order used.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!