This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.

4174. How does [atomics.order] p3 apply when then modification is an initialization?

Section: 32.5.4 [atomics.order] Status: New Submitter: jim x Opened: 2024-11-13 Last modified: 2024-11-24

Priority: Not Prioritized

View other active issues in [atomics.order].

View all other issues in [atomics.order].

View all issues with New status.

Discussion:

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 load and store operations ordered in the single total order? According to 32.5.4 [atomics.order] p3 (emphasize mine)

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

  1. […]

  2. (3.3) — 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

According to 32.5.8.2 [atomics.types.operations] p3 (emphasize mine)

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

So, how does 32.5.4 [atomics.order] p3 apply to this example such that the load operation precedes the store operation in the single total order S?

Proposed resolution: