Skip to content

What is the order of evaluations occurring within the store and load operations that have synchronize-with #740

@xmh0511

Description

@xmh0511

Full name of submitter (unless configured in github; will be published with the issue): Jim X

std::atomic<int> val = {0};

// thread 1:
val.store(1);

// thread 2:
val.load(); // read 1

Assuming the load reads the value written by val.store(1), so the store operation synchronizes with the load operation. [intro.races] p7 says:

An evaluation A happens before an evaluation B (or, equivalently, B happens after A) if either

  • [...]
  • A synchronizes with B, or

The evaluation is defined for expressions. So, saying A synchronizes with B means that the function call val.store() synchronizes with val.load() since they are the expressions. However, it's unclear what the evaluations occurring within the function invocation(val.store()) are ordered to the evaluations occurring within val.load()(if any).

[intro.execution] p12 does not apply here since it is defined for a single thread.

Additionally, consider this example:

int a = 0;
void fun(){
   a = 1;  // #0
}
int main(){
   fun();  // #1
   a = 2;  // #2
}

For this example, #2 is either sequenced before or after the evaluations(i.e. #0) occurring within the function invocation fun() according to [intro.execution] p12. [intro.execution] p9 only says that:

Every value computation and side effect associated with a full-expression is sequenced before every value computation and side effect associated with the next full-expression to be evaluated.

The full-expression at #1 is the function call expression, and the full-expression at #2 is the assignment-expression. There is no wording in the standard that says the evaluations occurring within a function call are all sequenced before the other expression E if the function call is sequenced before E.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions