|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4174" status="New"> |
| 5 | +<title>How does [atomics.order] p3 apply when then modification is an initialization?</title> |
| 6 | +<section><sref ref="[atomics.order]"/></section> |
| 7 | +<submitter>jim x</submitter> |
| 8 | +<date>13 Nov 2024</date> |
| 9 | +<priority>99</priority> |
| 10 | + |
| 11 | +<discussion> |
| 12 | +<p> |
| 13 | +Consider this example |
| 14 | +</p> |
| 15 | +<blockquote><pre> |
| 16 | +std::atomic<int> v = 0; |
| 17 | +// thread 1: |
| 18 | +v.load(std::memory_order::seq_cst); |
| 19 | +//thread 2: |
| 20 | +v.store(1,std::memory_order::seq_cst); |
| 21 | +</pre></blockquote> |
| 22 | +<p> |
| 23 | +If the load operation reads the value `0`, how are load and store operations ordered in the single total order? |
| 24 | +According to <sref ref="[atomics.order]"/> p3 (emphasize mine) |
| 25 | +</p> |
| 26 | +<blockquote style="border-left: 3px solid #ccc;padding-left: 15px;"> |
| 27 | +<p> |
| 28 | +An atomic operation <i>A</i> on some atomic object <i>M</i> is <i>coherence-ordered before</i> |
| 29 | +another atomic operation <i>B</i> on <i>M</i> if |
| 30 | +</p> |
| 31 | +<ol style="list-style-type: none"> |
| 32 | +<li><p>[…]</p></li> |
| 33 | +<li><p>(3.3) — <i>A</i> and <i>B</i> are not the same atomic read-modify-write operation, |
| 34 | +and there exists an <b>atomic modification <i>X</i></b> of <i>M</i> such that <i>A</i> reads the value stored by |
| 35 | +<i>X</i> and <i>X</i> precedes <i>B</i> in the modification order of <i>M</i>, or</p></li> |
| 36 | +</ol> |
| 37 | +</blockquote> |
| 38 | +<p> |
| 39 | +According to <sref ref="[atomics.types.operations]"/> p3 (emphasize mine) |
| 40 | +</p> |
| 41 | +<blockquote style="border-left: 3px solid #ccc;padding-left: 15px;"> |
| 42 | +<i>Effects</i>: Initializes the object with the value <tt>desired</tt>. <b>Initialization is not an atomic operation</b> |
| 43 | +(<sref ref="[intro.multithread]"/>). |
| 44 | +</blockquote> |
| 45 | +<p> |
| 46 | +So, how does <sref ref="[atomics.order]"/> p3 apply to this example such that the load operation precedes |
| 47 | +the store operation in the single total order <i>S</i>? |
| 48 | +</p> |
| 49 | +</discussion> |
| 50 | + |
| 51 | +<resolution> |
| 52 | +<p> |
| 53 | +</p> |
| 54 | +</resolution> |
| 55 | + |
| 56 | +</issue> |
0 commit comments