-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LWG3980 [atomics.ref.ops] p19 Where is the wording that forbids the read operation to read the same initial value? #423
Comments
[atomics.order] p10 maybe a relevant rule
However, this wording can have two interpretations
With the first interpretation, the initial value The second interpretation presumably is the intent of the wording. It may be clearer if we chang it to the following Suggest Resolution
|
The wording needs to be improved to make it readable. In the current wording, "before" has some ambiguities as said in the issue. |
Note "atomically" in [atomics.types.operations] p23. The read-compare-write is a single, indivisible operation ("atomically"). That's inconsistent with the idea that a second read-compare-write somehow would partially overlap (on the same atomic object). |
"atomically" does not have a formal interpretation in the current draft. Moreover, based on your interpretation of "atomically", the "atomically" seems to only apply to comparison, in which the read operation is unavoidable, not sure whether the "atomically" ultimately applies to that read. The "atomically" even needs to have meaning "non-interrupt" in this case. However, the
IMO, there can be more than one As @Eisenwave linked the related question, the answers seem to agree [atomics.order] p10 is that formal interpretation of the original issue, however, this wording is quite subtle and needs some decoration.
As exposed in Stackover flow / For purposes of ordering, is atomic read-modify-write one operation or two? and the answer in the question linked by @Eisenwave People have less or more confusion in this aspect, for example, the opinion in the answer
In certain circumstances, the read and write operations in a CAS_strong are separated. |
This issue is now https://cplusplus.github.io/LWG/issue3980 so I think it could be closed here. |
Full name of submitter (unless configured in github; will be published with the issue): Jim X
[atomics.types.operations] p23 says:
Consider this example:
This is the essence of implementing the "spinlock". However, in this example,
spin
is initialized with the valuefalse
, So, can the comparison in the two threads both read this initial valuefalse
and compare equally with the expected valuefalse
? IMO, there is no formal wording in the standard that forbids this possible. [intro.races] p14 just says:If they cannot, where does the relevant wording specify that this is impossible?
The text was updated successfully, but these errors were encountered: