Skip to content

LWG4174 [atomics.order] p3.3 The initialization to an atomic object is not a atomic operation #641

@xmh0511

Description

@xmh0511

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

Consider this example:

std::atomic<int> v = 0;
// thread 1:
v.load(std::memory_order::seq_cst);
//thread 2:
v.store(1,std::memory_order::seq_cst);

If the load operation reads the value 0, how are they ordered in the single total order? According to [atomics.order] p3

An atomic operation A on some atomic object M is coherence-ordered before another atomic operation B on M if

  • [...]
    A and B are not the same atomic read-modify-write operation, and there exists an atomic modification X of M such that A reads the value stored by X and X precedes B in the modification order of M, or

The initialization to v is not an atomic modification as per [atomics.types.operations] p3

Effects: Initializes the object with the value desired. Initialization is not an atomic operation ([intro.multithread]).

The initialization(i.e. X) precedes the store(i.e. B) in the modification order of v, however, X is not atomic modification, so, how does p3.3 apply to this case to determine the order of the load and store in the single total order?

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