cplusplus / cplusplus/draft

[atomics.order] p5 The note doesn't accurately express the meaning of the formal rules

Open
#8,771 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

P3-Other
Dominant language
TeX
Stars
221
Forks
813
Avg merge
16h 4m
Merged PRs (30d)
36

Description

[atomics.order] p5 says:

It also ensures that a memory_order::seq_cst load A of M gets its value either from the last modification of M that precedes A in S or from some non-memory_order::seq_cst modification of M that does not happen before any modification of M that precedes A in S.

The note is inaccurate because the emphasized part doesn't cover this case:

std::atomic<int> m = 0;
// thread 1:
m.store(1,std::memory_order::relaxed); // #1

// thread 2:
if(m.fetch_add(1,std::memory_order::seq_cst)==1){  // #2
   m.load(std::memory_order::seq_cst); // #3
}

#1 indeed does not happen before #2(however, #1 precedes #2 in the modification order of m), and #2 precedes #3 in S, however, #3 is impossible to read #1.

So, saying "does not happen before" is insufficient and doesn't accurately express the intent of the formal wording(especially, [atomics.order] p3 and p4).

Assuming X is any modification of M that precedes A in S, if A were to read any non-memory_order::seq_cst modification that precedes X in the modification order of M, [atomics.order] p3.3 would render that A is coherence-ordered before X, that is, A would precede X in S, which conflicts with the assumption that X precedes A in S. This means, if A doesn't read the last X, it must read some non-memory_order::seq_cst modification that follows X in the modification order of M.

Suggested Resolution:

or from some non-memory_order::seq_cst modification of M that does not precede any modification in the modification order of M that precedes A in S.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Search the draft sources for the [atomics.order] paragraph 5 wording quoted in the issue, then read paragraphs 3 and 4 to confirm the intended relationship. Update the note using the proposed wording and verify that it matches the formal rules and the supplied atomic example.

Written by the indexing model from the issue text.

Assessment

Tech stack
tex
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.