You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implementations should make atomic stores, which will be used by atomic loads visible within a reasonable amount of time.
No demand is made towards x.load(), so the following optimization is permissible:
bool b = should_wait.load();
while (b) { } // note: undefined behavior for b == false// because no forward progress is made
Due to this UB, it is also permissible to optimize it to:
[[assume(not should_wait)]];
Strict Reading
We can also interpret it as:
Implementations should make atomic loads use recent atomic stores within a reasonable amount of time.
This would make the above optimization invalid, despite the fact that x.load() isn't synchronized in any way.
Proposed Disambiguation
The strict reading is how users expect atomics to behave, and is also matching existing practice in implementations. The following wording is less ambiguous:
-Implementations should make atomic stores visible to atomic loads within a reasonable amount of time.+Implementations should make atomic stores visible to atomic loads,+and atomic loads should observe atomic stores,+both within a reasonable amount of time.
Note: the both is essential to avoid further ambiguity here.
The text was updated successfully, but these errors were encountered:
Can we make the phrasing a little more symmetric? for example:
"Atomic stores should be visible to atomic loads, and atomic loads should observe atomic stores, within a reasonable amount of time."
I don't like the suggested "both" placement; what's the ambiguity when leaving it out?
"Atomic stores should be visible to atomic loads, and atomic loads should observe atomic stores, within a reasonable amount of time."
I felt like the both is needed, but now that I'm reading it, the comma before within should be disambiguating enough, so that this doesn't just refer to loads.
The famous [atomics.order] p11 states:
I've recently argued about whether this paragraph makes demands towards atomic loads, or just stores. For example, we could have:
Relaxed Reading
We can interpret the paragraph as:
No demand is made towards
x.load()
, so the following optimization is permissible:Due to this UB, it is also permissible to optimize it to:
[[assume(not should_wait)]];
Strict Reading
We can also interpret it as:
This would make the above optimization invalid, despite the fact that
x.load()
isn't synchronized in any way.Proposed Disambiguation
The strict reading is how users expect atomics to behave, and is also matching existing practice in implementations. The following wording is less ambiguous:
Note: the both is essential to avoid further ambiguity here.
The text was updated successfully, but these errors were encountered: