Topic: For atomic<T> instances, is there a need for a memory
Author: "'Walt Karas' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Sat, 13 Aug 2016 16:55:24 -0700 (PDT)
Raw View
------=_Part_1479_617374303.1471132524556
Content-Type: multipart/alternative;
boundary="----=_Part_1480_725365478.1471132524556"
------=_Part_1480_725365478.1471132524556
Content-Type: text/plain; charset=UTF-8
For the code:
atomic<int> i;
int sum = i.load(memory_order_relaxed);
sum += i.load(memory_order_relaxed);
both clang and gcc will load i from memory twice. Was this the intent of
the Standard?
If an atomic instance is only ever written in a single thread, then loads
in that thread can correctly be optimized out I think. Do we need another
memory order (memory_order_none perhaps) to indicate loads of the instance
from memory are not necessary if the value of it is still in register(s)
(due to a preceding load or store)?
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/51b50bc6-941e-4c52-b124-6a0e98838a45%40isocpp.org.
------=_Part_1480_725365478.1471132524556
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">For the code:<div><br></div><div>atomic<int> i;</div=
><div>int sum =3D i.load(memory_order_relaxed);</div><div>sum +=3D i.load(m=
emory_order_relaxed);</div><div><br></div><div>both clang and gcc will load=
i from memory twice. =C2=A0Was this the intent of the Standard?</div><div>=
<br></div><div>If an atomic instance is only ever written in a single threa=
d, then loads in that thread can correctly be optimized out I think. =C2=A0=
Do we need another memory order (memory_order_none perhaps) to indicate loa=
ds of the instance from memory are not necessary if the value of it is stil=
l in register(s) (due to a preceding load or store)?</div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/51b50bc6-941e-4c52-b124-6a0e98838a45%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/51b50bc6-941e-4c52-b124-6a0e98838a45=
%40isocpp.org</a>.<br />
------=_Part_1480_725365478.1471132524556--
------=_Part_1479_617374303.1471132524556--
.