Topic: Runtime code generation and self modifying code


Author: Matthew Fioravante <fmatthew5876@gmail.com>
Date: Thu, 4 Oct 2018 17:35:50 -0700 (PDT)
Raw View
------=_Part_530_1020567351.1538699750987
Content-Type: multipart/alternative;
 boundary="----=_Part_531_1032808767.1538699750987"

------=_Part_531_1032808767.1538699750987
Content-Type: text/plain; charset="UTF-8"

One big area where dynamic languages are way ahead of C++ is runtime
dynamic code generation or self modifying code.


One tiny example is singleton initialization. The only safe way in C++ to
do non-constexpr singletons is by lazy init.

The problem with lazy init is that you have to pay for a branch on every
access, and that usually involves an atomic check.

What if you instead you atomically overwrote the check with NOPS. Then the
branch is gone and accessing the object is as efficient as if it weren't
lazy.

Has anyone considered writing proposals for improving runtime code gen with
C++?

--
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/4489f889-977c-45f2-8a2f-186ee3b06bff%40isocpp.org.

------=_Part_531_1032808767.1538699750987
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>One big area where dynamic languages are way ahead of=
 C++ is runtime dynamic code generation or self modifying code.<br></div><d=
iv><br></div><div><br></div><div>One tiny example is singleton initializati=
on. The only safe way in C++ to do non-constexpr singletons is by lazy init=
.. <br></div><div><br></div><div>The problem with lazy init is that you have=
 to pay for a branch on every access, and that usually involves an atomic c=
heck.</div><div><br></div><div>What if you instead you atomically overwrote=
 the check with NOPS. Then the branch is gone and accessing the object is a=
s efficient as if it weren&#39;t lazy.<br></div><div><br></div><div>Has any=
one considered writing proposals for improving runtime code gen with C++?<b=
r></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; 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/4489f889-977c-45f2-8a2f-186ee3b06bff%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/4489f889-977c-45f2-8a2f-186ee3b06bff=
%40isocpp.org</a>.<br />

------=_Part_531_1032808767.1538699750987--

------=_Part_530_1020567351.1538699750987--

.


Author: Ren Industries <renindustries@gmail.com>
Date: Thu, 4 Oct 2018 20:57:47 -0400
Raw View
--000000000000ce3d65057770c21c
Content-Type: text/plain; charset="UTF-8"

Couldn't a compiler just output that code for this idiom?
Sounds like a QOI issue.

On Thu, Oct 4, 2018 at 8:35 PM Matthew Fioravante <fmatthew5876@gmail.com>
wrote:

> One big area where dynamic languages are way ahead of C++ is runtime
> dynamic code generation or self modifying code.
>
>
> One tiny example is singleton initialization. The only safe way in C++ to
> do non-constexpr singletons is by lazy init.
>
> The problem with lazy init is that you have to pay for a branch on every
> access, and that usually involves an atomic check.
>
> What if you instead you atomically overwrote the check with NOPS. Then the
> branch is gone and accessing the object is as efficient as if it weren't
> lazy.
>
> Has anyone considered writing proposals for improving runtime code gen
> with C++?
>
> --
> 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/4489f889-977c-45f2-8a2f-186ee3b06bff%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/4489f889-977c-45f2-8a2f-186ee3b06bff%40isocpp.org?utm_medium=email&utm_source=footer>
> .
>

--
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/CAMD6iD_1Xqqa7Qjv35FaCH1Q39Jitr8Okwds-_2i0wWxz6EEYA%40mail.gmail.com.

--000000000000ce3d65057770c21c
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Couldn&#39;t a compiler just output that code for this idi=
om?<div>Sounds like a QOI issue.</div></div><br><div class=3D"gmail_quote">=
<div dir=3D"ltr">On Thu, Oct 4, 2018 at 8:35 PM Matthew Fioravante &lt;<a h=
ref=3D"mailto:fmatthew5876@gmail.com">fmatthew5876@gmail.com</a>&gt; wrote:=
<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;bord=
er-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>One big area=
 where dynamic languages are way ahead of C++ is runtime dynamic code gener=
ation or self modifying code.<br></div><div><br></div><div><br></div><div>O=
ne tiny example is singleton initialization. The only safe way in C++ to do=
 non-constexpr singletons is by lazy init. <br></div><div><br></div><div>Th=
e problem with lazy init is that you have to pay for a branch on every acce=
ss, and that usually involves an atomic check.</div><div><br></div><div>Wha=
t if you instead you atomically overwrote the check with NOPS. Then the bra=
nch is gone and accessing the object is as efficient as if it weren&#39;t l=
azy.<br></div><div><br></div><div>Has anyone considered writing proposals f=
or improving runtime code gen with C++?<br></div></div>

<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; 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" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">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/4489f889-977c-45f2-8a2f-186ee3b06bff%=
40isocpp.org?utm_medium=3Demail&amp;utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/4489f889-977c-=
45f2-8a2f-186ee3b06bff%40isocpp.org</a>.<br>
</blockquote></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; 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/CAMD6iD_1Xqqa7Qjv35FaCH1Q39Jitr8Okwds=
-_2i0wWxz6EEYA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">htt=
ps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAMD6iD_1Xqqa7Qjv=
35FaCH1Q39Jitr8Okwds-_2i0wWxz6EEYA%40mail.gmail.com</a>.<br />

--000000000000ce3d65057770c21c--

.


Author: Daniel Gutson <danielgutson@gmail.com>
Date: Fri, 5 Oct 2018 00:45:40 -0300
Raw View
--000000000000ae03de0577731b2e
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

No, just please don't.

SMC has tons of consequences, from security perspective (check
https://en.wikipedia.org/wiki/W%5EX and also triggering antivirus
heuristics) to performance perspective (breaking every single performance
prediction microproceesor feature).
Additionally, SMC is really hard to debug (check gdb, and --smc-check in
valgrind) and easy to crash (I have too vast experience with this).
I really don't see enough benefits.

El jue., 4 de oct. de 2018 a la(s) 21:35, Matthew Fioravante (
fmatthew5876@gmail.com) escribi=C3=B3:

> One big area where dynamic languages are way ahead of C++ is runtime
> dynamic code generation or self modifying code.
>
>
> One tiny example is singleton initialization. The only safe way in C++ to
> do non-constexpr singletons is by lazy init.
>
> The problem with lazy init is that you have to pay for a branch on every
> access, and that usually involves an atomic check.
>
> What if you instead you atomically overwrote the check with NOPS. Then th=
e
> branch is gone and accessing the object is as efficient as if it weren't
> lazy.
>
> Has anyone considered writing proposals for improving runtime code gen
> with C++?
>
> --
> 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/4489f889-977=
c-45f2-8a2f-186ee3b06bff%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/4489f889-97=
7c-45f2-8a2f-186ee3b06bff%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoot=
er>
> .
>


--=20
Who=E2=80=99s got the sweetest disposition?
One guess, that=E2=80=99s who?
Who=E2=80=99d never, ever start an argument?
Who never shows a bit of temperament?
Who's never wrong but always right?
Who'd never dream of starting a fight?
Who get stuck with all the bad luck?

--=20
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 e=
mail 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/CAFdMc-0gqidWj79ogvg8wdwx28N0N%2Bweecu%2B1dFe5mE=
zyLN9gg%40mail.gmail.com.

--000000000000ae03de0577731b2e
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr">No, just please don&#39;t.<div><br></div>=
<div>SMC has tons of consequences, from security perspective (check <a href=
=3D"https://en.wikipedia.org/wiki/W%5EX">https://en.wikipedia.org/wiki/W%5E=
X</a> and also triggering antivirus heuristics) to performance perspective =
(breaking every single performance prediction microproceesor feature).</div=
><div>Additionally, SMC is really hard to debug (check gdb, and --smc-check=
 in valgrind) and easy to crash (I have too vast experience with this).</di=
v><div>I really don&#39;t see enough benefits.</div></div></div><br><div cl=
ass=3D"gmail_quote"><div dir=3D"ltr">El jue., 4 de oct. de 2018 a la(s) 21:=
35, Matthew Fioravante (<a href=3D"mailto:fmatthew5876@gmail.com">fmatthew5=
876@gmail.com</a>) escribi=C3=B3:<br></div><blockquote class=3D"gmail_quote=
" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><=
div dir=3D"ltr"><div>One big area where dynamic languages are way ahead of =
C++ is runtime dynamic code generation or self modifying code.<br></div><di=
v><br></div><div><br></div><div>One tiny example is singleton initializatio=
n. The only safe way in C++ to do non-constexpr singletons is by lazy init.=
 <br></div><div><br></div><div>The problem with lazy init is that you have =
to pay for a branch on every access, and that usually involves an atomic ch=
eck.</div><div><br></div><div>What if you instead you atomically overwrote =
the check with NOPS. Then the branch is gone and accessing the object is as=
 efficient as if it weren&#39;t lazy.<br></div><div><br></div><div>Has anyo=
ne considered writing proposals for improving runtime code gen with C++?<br=
></div></div>

<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; 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" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">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/4489f889-977c-45f2-8a2f-186ee3b06bff%=
40isocpp.org?utm_medium=3Demail&amp;utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/4489f889-977c-=
45f2-8a2f-186ee3b06bff%40isocpp.org</a>.<br>
</blockquote></div><br clear=3D"all"><div><br></div>-- <br><div dir=3D"ltr"=
 class=3D"gmail_signature" data-smartmail=3D"gmail_signature">Who=E2=80=99s=
 got the sweetest disposition?<br>One guess, that=E2=80=99s who?<br>Who=E2=
=80=99d never, ever start an argument?<br>Who never shows a bit of temperam=
ent?<br>Who&#39;s never wrong but always right?<br>Who&#39;d never dream of=
 starting a fight?<br>Who get stuck with all the bad luck? </div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; 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/CAFdMc-0gqidWj79ogvg8wdwx28N0N%2Bweec=
u%2B1dFe5mEzyLN9gg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAFdMc-0gqidW=
j79ogvg8wdwx28N0N%2Bweecu%2B1dFe5mEzyLN9gg%40mail.gmail.com</a>.<br />

--000000000000ae03de0577731b2e--

.


Author: Andrew Sandoval <sandoval@netwaysglobal.com>
Date: Thu, 4 Oct 2018 23:17:33 -0500
Raw View
--000000000000b020b30577738d46
Content-Type: text/plain; charset="UTF-8"

Working the security side of this I can tell you emphatically that JIT code
and self-modifying code are two of the worst things ever to be utilized,
especially within Web Browsers, etc.  If we could eliminate JIT engines
altogether we'd eliminate a ton of software vulnerabilities.  Sadly most
JIT engines leak writable, executable memory for extended periods of time.
We finally have compilers that generate checks for stack overflows, etc.,
and we have DEP, only to have it somewhat ruined by JIT'd code, packers,
and self-modifying code, etc.

I'd rather pay the cost of an atomic operation any day compared to the cost
of changing page table entries to make executable memory writable +
executable, and then (hopefully) back to just executable.  Because even
then you still leave a small window open where something can trample your
executable memory, slipping in a call, jmp, or a well placed exception such
as divide-by-zero or a invalid instruction or any other number of abuses.

-Andrew

On Thu, Oct 4, 2018 at 7:35 PM Matthew Fioravante <fmatthew5876@gmail.com>
wrote:

> One big area where dynamic languages are way ahead of C++ is runtime
> dynamic code generation or self modifying code.
>
>
> One tiny example is singleton initialization. The only safe way in C++ to
> do non-constexpr singletons is by lazy init.
>
> The problem with lazy init is that you have to pay for a branch on every
> access, and that usually involves an atomic check.
>
> What if you instead you atomically overwrote the check with NOPS. Then the
> branch is gone and accessing the object is as efficient as if it weren't
> lazy.
>
> Has anyone considered writing proposals for improving runtime code gen
> with C++?
>
> --
> 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/4489f889-977c-45f2-8a2f-186ee3b06bff%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/4489f889-977c-45f2-8a2f-186ee3b06bff%40isocpp.org?utm_medium=email&utm_source=footer>
> .
>


--
*Andrew L. Sandoval*
sandoval@netwaysglobal.com

[image: qrcode] <http://mormon.org/me/72HW/>

--
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/CAJEeERU%2B5x5VuPFBTKizOzK-U2AeUZEc9W9-sD508%2BsPSfK4fg%40mail.gmail.com.

--000000000000b020b30577738d46
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Working the security side of this I can tell you emphatica=
lly that JIT code and self-modifying code are two of the worst things ever =
to be utilized, especially within Web Browsers, etc.=C2=A0 If we could elim=
inate JIT engines altogether we&#39;d eliminate a ton of software vulnerabi=
lities.=C2=A0 Sadly most JIT engines leak writable, executable memory for e=
xtended periods of time.=C2=A0 We finally have compilers that generate chec=
ks for stack overflows, etc., and we have DEP, only to have it somewhat rui=
ned by JIT&#39;d code, packers, and self-modifying code, etc.<div><br></div=
><div>I&#39;d rather pay the cost of an atomic operation any day compared t=
o the cost of changing page table entries to make executable memory writabl=
e + executable, and then (hopefully) back to just executable.=C2=A0 Because=
 even then you still leave a small window open where something can trample =
your executable memory, slipping in a call, jmp, or a well placed exception=
 such as divide-by-zero or a invalid instruction or any other number of abu=
ses.</div><div><br></div><div>-Andrew</div></div><br><div class=3D"gmail_qu=
ote"><div dir=3D"ltr">On Thu, Oct 4, 2018 at 7:35 PM Matthew Fioravante &lt=
;<a href=3D"mailto:fmatthew5876@gmail.com">fmatthew5876@gmail.com</a>&gt; w=
rote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex=
;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>One big=
 area where dynamic languages are way ahead of C++ is runtime dynamic code =
generation or self modifying code.<br></div><div><br></div><div><br></div><=
div>One tiny example is singleton initialization. The only safe way in C++ =
to do non-constexpr singletons is by lazy init. <br></div><div><br></div><d=
iv>The problem with lazy init is that you have to pay for a branch on every=
 access, and that usually involves an atomic check.</div><div><br></div><di=
v>What if you instead you atomically overwrote the check with NOPS. Then th=
e branch is gone and accessing the object is as efficient as if it weren&#3=
9;t lazy.<br></div><div><br></div><div>Has anyone considered writing propos=
als for improving runtime code gen with C++?<br></div></div>

<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; 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" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">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/4489f889-977c-45f2-8a2f-186ee3b06bff%=
40isocpp.org?utm_medium=3Demail&amp;utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/4489f889-977c-=
45f2-8a2f-186ee3b06bff%40isocpp.org</a>.<br>
</blockquote></div><br clear=3D"all"><div><br></div>-- <br><div dir=3D"ltr"=
 class=3D"gmail_signature" data-smartmail=3D"gmail_signature"><font size=3D=
"4"><b style=3D"color:rgb(153,0,0);font-family:comic sans ms,sans-serif">An=
drew L. Sandoval</b></font><br><span style=3D"font-family:courier new,monos=
pace"><a href=3D"mailto:sandoval@netwaysglobal.com" target=3D"_blank">sando=
val@netwaysglobal.com</a></span><br><br><a href=3D"http://mormon.org/me/72H=
W/" target=3D"_blank"><img src=3D"http://qrcode.kaywa.com/img.php?s=3D5&amp=
;d=3Dhttp%3A%2F%2Fmormon.org%2Fme%2F72HW%2F" alt=3D"qrcode" height=3D"62" w=
idth=3D"62"></a><br></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; 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/CAJEeERU%2B5x5VuPFBTKizOzK-U2AeUZEc9W=
9-sD508%2BsPSfK4fg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAJEeERU%2B5x=
5VuPFBTKizOzK-U2AeUZEc9W9-sD508%2BsPSfK4fg%40mail.gmail.com</a>.<br />

--000000000000b020b30577738d46--

.


Author: florian.csdt@gmail.com
Date: Fri, 5 Oct 2018 01:40:20 -0700 (PDT)
Raw View
------=_Part_630_828919830.1538728820261
Content-Type: multipart/alternative;
 boundary="----=_Part_631_1054089242.1538728820262"

------=_Part_631_1054089242.1538728820262
Content-Type: text/plain; charset="UTF-8"

Also, such a "modifying" code is already implementable now, and is already
used for shared object linking: jumping to a mutable pointer.

int* p = nullptr;
int* init_p();
int*(*get_p)() = &init_p;

int* noinit_p() {
  return p;
}
int* init_p() {
  // needs atomic here
  if (!p) {
    p = new int();
  }

  // needs atomic also here
  get_p = &noinit_p;

  return p;
}


--
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/e20ce6f4-d93e-4bdd-a17f-c36d63c48d55%40isocpp.org.

------=_Part_631_1054089242.1538728820262
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Also, such a &quot;modifying&quot; code is already im=
plementable now, and is already used for shared object linking: jumping to =
a mutable pointer.</div><div><br></div><div><div style=3D"background-color:=
 rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid;=
 border-width: 1px; overflow-wrap: break-word;" class=3D"prettyprint"><code=
 class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: =
#008;" class=3D"styled-by-prettify">int</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">*</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> p </span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">nul=
lptr</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">int</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">*</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> init_p</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">();</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">int</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">*(*</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify">get_p</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">)()</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">&amp;</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify">init_p</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"><br><br></span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">int</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">*</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> noinit_p</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">()</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 </sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">return</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> p</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">int</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">*</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> init_p</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
()</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 </span><span st=
yle=3D"color: #800;" class=3D"styled-by-prettify">// needs atomic here</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 </sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">if</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">(!</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify">p</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br>=C2=A0 =C2=A0 p </span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">new</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
 style=3D"color: #008;" class=3D"styled-by-prettify">int</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">();</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br>=C2=A0 </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br><br>=C2=A0 </span><span style=3D"color:=
 #800;" class=3D"styled-by-prettify">// needs atomic also here</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 get_p </span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">&amp;</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">noinit_p</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br><br>=C2=A0 </span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">return</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> p</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
</span></div></code></div><br><br> </div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; 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/e20ce6f4-d93e-4bdd-a17f-c36d63c48d55%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/e20ce6f4-d93e-4bdd-a17f-c36d63c48d55=
%40isocpp.org</a>.<br />

------=_Part_631_1054089242.1538728820262--

------=_Part_630_828919830.1538728820261--

.


Author: Thiago Macieira <thiago@macieira.org>
Date: Fri, 05 Oct 2018 08:38:39 -0700
Raw View
On Thursday, 4 October 2018 17:35:50 PDT Matthew Fioravante wrote:
> What if you instead you atomically overwrote the check with NOPS. Then the
> branch is gone and accessing the object is as efficient as if it weren't
> lazy.

You can't do that on most modern architectures.

--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center



--
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/85554521.NQMVqEWYve%40tjmaciei-mobl1.

.


Author: Rene Rivera <grafikrobot@gmail.com>
Date: Fri, 5 Oct 2018 10:48:17 -0500
Raw View
--000000000000e641c105777d3323
Content-Type: text/plain; charset="UTF-8"

While I understand, and concur, with others statements regarding code
generation in the context of the the host program.. There are valid use
cases for dynamic code generation. For example targeting emulators and
GPUs. So perhaps you might want to rephrase your ideas in those terms.


On Thu, Oct 4, 2018 at 7:35 PM Matthew Fioravante <fmatthew5876@gmail.com>
wrote:

> One big area where dynamic languages are way ahead of C++ is runtime
> dynamic code generation or self modifying code.
>
>
> One tiny example is singleton initialization. The only safe way in C++ to
> do non-constexpr singletons is by lazy init.
>
> The problem with lazy init is that you have to pay for a branch on every
> access, and that usually involves an atomic check.
>
> What if you instead you atomically overwrote the check with NOPS. Then the
> branch is gone and accessing the object is as efficient as if it weren't
> lazy.
>
> Has anyone considered writing proposals for improving runtime code gen
> with C++?
>
> --
> 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/4489f889-977c-45f2-8a2f-186ee3b06bff%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/4489f889-977c-45f2-8a2f-186ee3b06bff%40isocpp.org?utm_medium=email&utm_source=footer>
> .
>


--
-- Rene Rivera
-- Grafik - Don't Assume Anything
-- Robot Dreams - http://robot-dreams.net

--
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/CAHEh_GiUrVM%3Da7QK%2BiNuXqFwxXCLyMA7WiRfWmHo_qmceV9JSw%40mail.gmail.com.

--000000000000e641c105777d3323
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">While I understand, and concur, with others statements reg=
arding code generation in the context of the the host program.. There are v=
alid use cases for dynamic code generation. For example targeting emulators=
 and GPUs. So perhaps you might want to rephrase your ideas in those terms.=
<div><br><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Thu, Oct 4, 201=
8 at 7:35 PM Matthew Fioravante &lt;<a href=3D"mailto:fmatthew5876@gmail.co=
m">fmatthew5876@gmail.com</a>&gt; wrote:<br></div><blockquote class=3D"gmai=
l_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left=
:1ex"><div dir=3D"ltr"><div>One big area where dynamic languages are way ah=
ead of C++ is runtime dynamic code generation or self modifying code.<br></=
div><div><br></div><div><br></div><div>One tiny example is singleton initia=
lization. The only safe way in C++ to do non-constexpr singletons is by laz=
y init. <br></div><div><br></div><div>The problem with lazy init is that yo=
u have to pay for a branch on every access, and that usually involves an at=
omic check.</div><div><br></div><div>What if you instead you atomically ove=
rwrote the check with NOPS. Then the branch is gone and accessing the objec=
t is as efficient as if it weren&#39;t lazy.<br></div><div><br></div><div>H=
as anyone considered writing proposals for improving runtime code gen with =
C++?<br></div></div>

<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; 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" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">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/4489f889-977c-45f2-8a2f-186ee3b06bff%=
40isocpp.org?utm_medium=3Demail&amp;utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/4489f889-977c-=
45f2-8a2f-186ee3b06bff%40isocpp.org</a>.<br>
</blockquote></div><br clear=3D"all"><div><br></div>-- <br><div dir=3D"ltr"=
 class=3D"gmail_signature" data-smartmail=3D"gmail_signature"><div dir=3D"l=
tr"><div><div dir=3D"ltr">-- Rene Rivera<br>-- Grafik - Don&#39;t Assume An=
ything<br>-- Robot Dreams -=C2=A0<a href=3D"http://robot-dreams.net/" targe=
t=3D"_blank">http://robot-dreams.net</a><br><br></div></div></div></div></d=
iv></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; 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/CAHEh_GiUrVM%3Da7QK%2BiNuXqFwxXCLyMA7=
WiRfWmHo_qmceV9JSw%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAHEh_GiUrVM%=
3Da7QK%2BiNuXqFwxXCLyMA7WiRfWmHo_qmceV9JSw%40mail.gmail.com</a>.<br />

--000000000000e641c105777d3323--

.


Author: Daniel Gutson <danielgutson@gmail.com>
Date: Fri, 5 Oct 2018 12:50:18 -0300
Raw View
--0000000000001df48005777d3b1f
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

El vie., 5 de oct. de 2018 a la(s) 12:48, Rene Rivera (grafikrobot@gmail.co=
m)
escribi=C3=B3:

> While I understand, and concur, with others statements regarding code
> generation in the context of the the host program.. There are valid use
> cases for dynamic code generation. For example targeting emulators and
> GPUs. So perhaps you might want to rephrase your ideas in those terms.
>

former qemu developer here.
It is a super specific case, which should be handled by a library in the
best of cases.


>
>
> On Thu, Oct 4, 2018 at 7:35 PM Matthew Fioravante <fmatthew5876@gmail.com=
>
> wrote:
>
>> One big area where dynamic languages are way ahead of C++ is runtime
>> dynamic code generation or self modifying code.
>>
>>
>> One tiny example is singleton initialization. The only safe way in C++ t=
o
>> do non-constexpr singletons is by lazy init.
>>
>> The problem with lazy init is that you have to pay for a branch on every
>> access, and that usually involves an atomic check.
>>
>> What if you instead you atomically overwrote the check with NOPS. Then
>> the branch is gone and accessing the object is as efficient as if it
>> weren't lazy.
>>
>> Has anyone considered writing proposals for improving runtime code gen
>> with C++?
>>
>> --
>> You received this message because you are subscribed to the Google Group=
s
>> "ISO C++ Standard - Future Proposals" group.
>> To unsubscribe from this group and stop receiving emails from it, send a=
n
>> 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/4489f889-97=
7c-45f2-8a2f-186ee3b06bff%40isocpp.org
>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/4489f889-9=
77c-45f2-8a2f-186ee3b06bff%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoo=
ter>
>> .
>>
>
>
> --
> -- Rene Rivera
> -- Grafik - Don't Assume Anything
> -- Robot Dreams - http://robot-dreams.net
>
> --
> 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/CAHEh_GiUrVM=
%3Da7QK%2BiNuXqFwxXCLyMA7WiRfWmHo_qmceV9JSw%40mail.gmail.com
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAHEh_GiUrV=
M%3Da7QK%2BiNuXqFwxXCLyMA7WiRfWmHo_qmceV9JSw%40mail.gmail.com?utm_medium=3D=
email&utm_source=3Dfooter>
> .
>


--=20
Who=E2=80=99s got the sweetest disposition?
One guess, that=E2=80=99s who?
Who=E2=80=99d never, ever start an argument?
Who never shows a bit of temperament?
Who's never wrong but always right?
Who'd never dream of starting a fight?
Who get stuck with all the bad luck?

--=20
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 e=
mail 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/CAFdMc-1qjWOE-7xWG%2BX01x9hO0jy-97qoeP89z%2Bjf0%=
2BzuxxY-Q%40mail.gmail.com.

--0000000000001df48005777d3b1f
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br><div class=3D"gmail_quote"><div dir=3D"ltr">El vie=
.., 5 de oct. de 2018 a la(s) 12:48, Rene Rivera (<a href=3D"mailto:grafikro=
bot@gmail.com">grafikrobot@gmail.com</a>) escribi=C3=B3:<br></div><blockquo=
te class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc so=
lid;padding-left:1ex"><div dir=3D"ltr">While I understand, and concur, with=
 others statements regarding code generation in the context of the the host=
 program.. There are valid use cases for dynamic code generation. For examp=
le targeting emulators and GPUs. So perhaps you might want to rephrase your=
 ideas in those terms.</div></blockquote><div><br></div><div>former qemu de=
veloper here.</div><div>It is a super specific case, which should be handle=
d by a library in the best of cases.</div><div>=C2=A0</div><blockquote clas=
s=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;pad=
ding-left:1ex"><div dir=3D"ltr"><div><br><br><div class=3D"gmail_quote"><di=
v dir=3D"ltr">On Thu, Oct 4, 2018 at 7:35 PM Matthew Fioravante &lt;<a href=
=3D"mailto:fmatthew5876@gmail.com" target=3D"_blank">fmatthew5876@gmail.com=
</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:=
0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><d=
iv>One big area where dynamic languages are way ahead of C++ is runtime dyn=
amic code generation or self modifying code.<br></div><div><br></div><div><=
br></div><div>One tiny example is singleton initialization. The only safe w=
ay in C++ to do non-constexpr singletons is by lazy init. <br></div><div><b=
r></div><div>The problem with lazy init is that you have to pay for a branc=
h on every access, and that usually involves an atomic check.</div><div><br=
></div><div>What if you instead you atomically overwrote the check with NOP=
S. Then the branch is gone and accessing the object is as efficient as if i=
t weren&#39;t lazy.<br></div><div><br></div><div>Has anyone considered writ=
ing proposals for improving runtime code gen with C++?<br></div></div>

<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; 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" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">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/4489f889-977c-45f2-8a2f-186ee3b06bff%=
40isocpp.org?utm_medium=3Demail&amp;utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/4489f889-977c-=
45f2-8a2f-186ee3b06bff%40isocpp.org</a>.<br>
</blockquote></div><br clear=3D"all"><div><br></div>-- <br><div dir=3D"ltr"=
 class=3D"m_3651805369659113589gmail_signature" data-smartmail=3D"gmail_sig=
nature"><div dir=3D"ltr"><div><div dir=3D"ltr">-- Rene Rivera<br>-- Grafik =
- Don&#39;t Assume Anything<br>-- Robot Dreams -=C2=A0<a href=3D"http://rob=
ot-dreams.net/" target=3D"_blank">http://robot-dreams.net</a><br><br></div>=
</div></div></div></div></div>

<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; 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" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">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/CAHEh_GiUrVM%3Da7QK%2BiNuXqFwxXCLyMA7=
WiRfWmHo_qmceV9JSw%40mail.gmail.com?utm_medium=3Demail&amp;utm_source=3Dfoo=
ter" target=3D"_blank">https://groups.google.com/a/isocpp.org/d/msgid/std-p=
roposals/CAHEh_GiUrVM%3Da7QK%2BiNuXqFwxXCLyMA7WiRfWmHo_qmceV9JSw%40mail.gma=
il.com</a>.<br>
</blockquote></div><br clear=3D"all"><div><br></div>-- <br><div dir=3D"ltr"=
 class=3D"gmail_signature" data-smartmail=3D"gmail_signature">Who=E2=80=99s=
 got the sweetest disposition?<br>One guess, that=E2=80=99s who?<br>Who=E2=
=80=99d never, ever start an argument?<br>Who never shows a bit of temperam=
ent?<br>Who&#39;s never wrong but always right?<br>Who&#39;d never dream of=
 starting a fight?<br>Who get stuck with all the bad luck? </div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; 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/CAFdMc-1qjWOE-7xWG%2BX01x9hO0jy-97qoe=
P89z%2Bjf0%2BzuxxY-Q%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfoote=
r">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAFdMc-1qjW=
OE-7xWG%2BX01x9hO0jy-97qoeP89z%2Bjf0%2BzuxxY-Q%40mail.gmail.com</a>.<br />

--0000000000001df48005777d3b1f--

.


Author: inkwizytoryankes@gmail.com
Date: Sat, 6 Oct 2018 10:25:47 -0700 (PDT)
Raw View
------=_Part_1071_2126836832.1538846747463
Content-Type: multipart/alternative;
 boundary="----=_Part_1072_228433328.1538846747464"

------=_Part_1072_228433328.1538846747464
Content-Type: text/plain; charset="UTF-8"



On Friday, October 5, 2018 at 2:58:02 AM UTC+2, Ren Industries wrote:
>
> Couldn't a compiler just output that code for this idiom?
> Sounds like a QOI issue.
>
>
Could use of thread locals could improve this situation? You could store
info if variable was already check, if not we go current path if yes then
we can skip memory barrier.

Only thing that current we can do is use function with `static` is return
pointer for future use:
X& init()
{
  static X a{ };
  return a;
}

void foo(X& stored) //free of cost
{
  stored.bar();
}

int main()
{
  foo(init()); //only main pay cost of init
}

auto& global_x = init(); //this could work too




> On Thu, Oct 4, 2018 at 8:35 PM Matthew Fioravante <fmatth...@gmail.com
> <javascript:>> wrote:
>
>> One big area where dynamic languages are way ahead of C++ is runtime
>> dynamic code generation or self modifying code.
>>
>>
>> One tiny example is singleton initialization. The only safe way in C++ to
>> do non-constexpr singletons is by lazy init.
>>
>> The problem with lazy init is that you have to pay for a branch on every
>> access, and that usually involves an atomic check.
>>
>> What if you instead you atomically overwrote the check with NOPS. Then
>> the branch is gone and accessing the object is as efficient as if it
>> weren't lazy.
>>
>> Has anyone considered writing proposals for improving runtime code gen
>> with C++?
>>
>> --
>> 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-proposal...@isocpp.org <javascript:>.
>> To post to this group, send email to std-pr...@isocpp.org <javascript:>.
>> To view this discussion on the web visit
>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/4489f889-977c-45f2-8a2f-186ee3b06bff%40isocpp.org
>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/4489f889-977c-45f2-8a2f-186ee3b06bff%40isocpp.org?utm_medium=email&utm_source=footer>
>> .
>>
>

--
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/4503e7f2-de35-413f-a0d6-3d637c0609e9%40isocpp.org.

------=_Part_1072_228433328.1538846747464
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Friday, October 5, 2018 at 2:58:02 AM UTC+2, Re=
n Industries wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;mar=
gin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D=
"ltr">Couldn&#39;t a compiler just output that code for this idiom?<div>Sou=
nds like a QOI issue.</div></div><br></blockquote><div><br></div><div>Could=
 use of thread locals could improve this situation? You could store info if=
 variable was already check, if not we go current path if yes then we can s=
kip memory barrier.</div><div><br></div><div>Only thing that current we can=
 do is use function with `static` is return pointer for future use:</div><d=
iv><div style=3D"background-color: rgb(250, 250, 250); border-color: rgb(18=
7, 187, 187); border-style: solid; border-width: 1px; overflow-wrap: break-=
word;" class=3D"prettyprint"><code class=3D"prettyprint"><div class=3D"subp=
rettyprint"><span style=3D"color: #000;" class=3D"styled-by-prettify">X</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">&amp;</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> init</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">()</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"><br>=C2=A0 </span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">static</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> X a</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=
=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">return=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> a</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br><br></span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">void</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> foo</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify">X</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>&amp;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> sto=
red</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span st=
yle=3D"color: #800;" class=3D"styled-by-prettify">//free of cost</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br>=C2=A0 stored</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">bar</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">();</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br><br></span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">int</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 main</span><span style=3D"color: #660;" class=3D"styled-by-prettify">()</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 foo</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">init</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">());</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> </span><span style=3D"color: #800;" class=3D=
"styled-by-prettify">//only main pay cost of init</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br><br></span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">auto</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">&amp;</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> global_x </span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> init</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>();</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #800;" class=3D"styled-by-prettify">//this could wo=
rk too</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
</span></div></code></div><br><br></div><div>=C2=A0</div><blockquote class=
=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #cc=
c solid;padding-left: 1ex;"><div class=3D"gmail_quote"><div dir=3D"ltr">On =
Thu, Oct 4, 2018 at 8:35 PM Matthew Fioravante &lt;<a href=3D"javascript:" =
target=3D"_blank" gdf-obfuscated-mailto=3D"usfcD_P7AgAJ" rel=3D"nofollow" o=
nmousedown=3D"this.href=3D&#39;javascript:&#39;;return true;" onclick=3D"th=
is.href=3D&#39;javascript:&#39;;return true;">fmatth...@gmail.com</a>&gt; w=
rote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex=
;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>One big=
 area where dynamic languages are way ahead of C++ is runtime dynamic code =
generation or self modifying code.<br></div><div><br></div><div><br></div><=
div>One tiny example is singleton initialization. The only safe way in C++ =
to do non-constexpr singletons is by lazy init. <br></div><div><br></div><d=
iv>The problem with lazy init is that you have to pay for a branch on every=
 access, and that usually involves an atomic check.</div><div><br></div><di=
v>What if you instead you atomically overwrote the check with NOPS. Then th=
e branch is gone and accessing the object is as efficient as if it weren&#3=
9;t lazy.<br></div><div><br></div><div>Has anyone considered writing propos=
als for improving runtime code gen with C++?<br></div></div>

<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"=
usfcD_P7AgAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;javascript:&=
#39;;return true;" onclick=3D"this.href=3D&#39;javascript:&#39;;return true=
;">std-proposal...@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"javascript:" target=3D"_bla=
nk" gdf-obfuscated-mailto=3D"usfcD_P7AgAJ" rel=3D"nofollow" onmousedown=3D"=
this.href=3D&#39;javascript:&#39;;return true;" onclick=3D"this.href=3D&#39=
;javascript:&#39;;return true;">std-pr...@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/4489f889-977c-45f2-8a2f-186ee3b06bff%=
40isocpp.org?utm_medium=3Demail&amp;utm_source=3Dfooter" target=3D"_blank" =
rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/4489f889-977c-45f2-8a2f-186ee3b06bff%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" on=
click=3D"this.href=3D&#39;https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/4489f889-977c-45f2-8a2f-186ee3b06bff%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/4489f889-977c-45f2-<wbr>8a2f-=
186ee3b06bff%40isocpp.org</a><wbr>.<br>
</blockquote></div>
</blockquote></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; 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/4503e7f2-de35-413f-a0d6-3d637c0609e9%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/4503e7f2-de35-413f-a0d6-3d637c0609e9=
%40isocpp.org</a>.<br />

------=_Part_1072_228433328.1538846747464--

------=_Part_1071_2126836832.1538846747463--

.


Author: inkwizytoryankes@gmail.com
Date: Sat, 6 Oct 2018 11:22:15 -0700 (PDT)
Raw View
------=_Part_1228_402401588.1538850135223
Content-Type: multipart/alternative;
 boundary="----=_Part_1229_1584657147.1538850135224"

------=_Part_1229_1584657147.1538850135224
Content-Type: text/plain; charset="UTF-8"

I probably have better solution: Great Memory Flush

We have:
One global counter that use only `memory_order_seq_cst`
Thread local copy of this global counter (it will be updated to current
value).
Each static variable have atomic variable that store old value of global
counter.

Algorithm will look something like that:

if (__static_var_counter > __thread_local_counter) //this could be even not atomic
access
{
    if (__static_var_counter != NOT_INIT)
    {
        __thread_local_counter = __great_memory_counter.load(
memory_order_seq_cst);
    }
    else
    {
        __init_var(); //can lock
        __static_var_counter = __great_memory_counter.inc(
memory_order_seq_cst);
        __thread_local_counter = __static_var_counter;
    }
}

If static variable value is less than current thread value the we can
safely access memory protected by this variable. Because we already reload
memory some time ago.
If we encounter sequence of static variables:
static int x;
static int y;
static int z;
We can check only for last if it variable is less than current thread value
and then skip whole block of initialization.


On Saturday, October 6, 2018 at 7:25:47 PM UTC+2, Marcin Jaczewski wrote:
>
>
>
> On Friday, October 5, 2018 at 2:58:02 AM UTC+2, Ren Industries wrote:
>>
>> Couldn't a compiler just output that code for this idiom?
>> Sounds like a QOI issue.
>>
>>
> Could use of thread locals could improve this situation? You could store
> info if variable was already check, if not we go current path if yes then
> we can skip memory barrier.
>
> Only thing that current we can do is use function with `static` is return
> pointer for future use:
> X& init()
> {
>   static X a{ };
>   return a;
> }
>
> void foo(X& stored) //free of cost
> {
>   stored.bar();
> }
>
> int main()
> {
>   foo(init()); //only main pay cost of init
> }
>
> auto& global_x = init(); //this could work too
>
>
>
>
>> On Thu, Oct 4, 2018 at 8:35 PM Matthew Fioravante <fmatth...@gmail.com>
>> wrote:
>>
>>> One big area where dynamic languages are way ahead of C++ is runtime
>>> dynamic code generation or self modifying code.
>>>
>>>
>>> One tiny example is singleton initialization. The only safe way in C++
>>> to do non-constexpr singletons is by lazy init.
>>>
>>> The problem with lazy init is that you have to pay for a branch on every
>>> access, and that usually involves an atomic check.
>>>
>>> What if you instead you atomically overwrote the check with NOPS. Then
>>> the branch is gone and accessing the object is as efficient as if it
>>> weren't lazy.
>>>
>>> Has anyone considered writing proposals for improving runtime code gen
>>> with C++?
>>>
>>> --
>>> 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-proposal...@isocpp.org.
>>> To post to this group, send email to std-pr...@isocpp.org.
>>> To view this discussion on the web visit
>>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/4489f889-977c-45f2-8a2f-186ee3b06bff%40isocpp.org
>>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/4489f889-977c-45f2-8a2f-186ee3b06bff%40isocpp.org?utm_medium=email&utm_source=footer>
>>> .
>>>
>>

--
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/649745f6-d2ff-4a01-bb51-964ba48ea1ee%40isocpp.org.

------=_Part_1229_1584657147.1538850135224
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>I probably have better solution: Great Memory Flush<b=
r></div><div><br></div><div>We have:</div><div>One global counter that use =
only `memory_order_seq_cst`</div><div>Thread local copy of this global coun=
ter (it will be updated to current value).</div><div>Each static variable h=
ave atomic variable that store old value of global counter.</div><div><br><=
/div><div>Algorithm will look something like that:</div><div><br></div><div=
><div style=3D"background-color: rgb(250, 250, 250); border-color: rgb(187,=
 187, 187); border-style: solid; border-width: 1px; overflow-wrap: break-wo=
rd;" class=3D"prettyprint"><code class=3D"prettyprint"><div class=3D"subpre=
ttyprint"><span style=3D"color: #008;" class=3D"styled-by-prettify">if</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">__static_var_counter </span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> __thread_local_counter</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #800;" class=3D"styled-by-prettify">//this could be even not </span><=
span style=3D"color: #800;" class=3D"styled-by-prettify">atomic access</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">if</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify">__static_var_counter </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">!=3D</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> NOT_INIT</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 __thread_local_coun=
ter </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> __great_memo=
ry_counter</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
..</span><span style=3D"color: #000;" class=3D"styled-by-prettify">load</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify">memory_order_seq_cst</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">);</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">else</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 __init_var</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">();</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #800;" class=3D"styled-by-prettify">//can=
 lock</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 __static_var_counter </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> __great_memory_counter</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">inc</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">memory_order_seq_cst</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">);</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 __thread_local_co=
unter </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> __static_v=
ar_counter</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=
=A0 =C2=A0 </span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span></div>=
</code></div><br>If static variable value is less than current thread value=
 the we can safely access memory protected by this variable. Because we alr=
eady reload memory some time ago. <br></div><div>If we encounter sequence o=
f static variables:</div><div><div style=3D"background-color: rgb(250, 250,=
 250); border-color: rgb(187, 187, 187); border-style: solid; border-width:=
 1px; overflow-wrap: break-word;" class=3D"prettyprint"><code class=3D"pret=
typrint"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=
=3D"styled-by-prettify">static</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">int</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> x</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">static</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">int</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> y</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"styled-=
by-prettify">static</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
int</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> z</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div></code>=
</div>We can check only for last if it variable is less than current thread=
 value and then skip whole block of initialization.<br><br></div><br>On Sat=
urday, October 6, 2018 at 7:25:47 PM UTC+2, Marcin Jaczewski wrote:<blockqu=
ote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left=
: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><br><br>On Friday, Oc=
tober 5, 2018 at 2:58:02 AM UTC+2, Ren Industries wrote:<blockquote class=
=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc s=
olid;padding-left:1ex"><div dir=3D"ltr">Couldn&#39;t a compiler just output=
 that code for this idiom?<div>Sounds like a QOI issue.</div></div><br></bl=
ockquote><div><br></div><div>Could use of thread locals could improve this =
situation? You could store info if variable was already check, if not we go=
 current path if yes then we can skip memory barrier.</div><div><br></div><=
div>Only thing that current we can do is use function with `static` is retu=
rn pointer for future use:</div><div><div style=3D"background-color:rgb(250=
,250,250);border-color:rgb(187,187,187);border-style:solid;border-width:1px=
"><code><div><span style=3D"color:#000">X</span><span style=3D"color:#660">=
&amp;</span><span style=3D"color:#000"> init</span><span style=3D"color:#66=
0">()</span><span style=3D"color:#000"><br></span><span style=3D"color:#660=
">{</span><span style=3D"color:#000"><br>=C2=A0 </span><span style=3D"color=
:#008">static</span><span style=3D"color:#000"> X a</span><span style=3D"co=
lor:#660">{</span><span style=3D"color:#000"> </span><span style=3D"color:#=
660">};</span><span style=3D"color:#000"><br>=C2=A0 </span><span style=3D"c=
olor:#008">return</span><span style=3D"color:#000"> a</span><span style=3D"=
color:#660">;</span><span style=3D"color:#000"><br></span><span style=3D"co=
lor:#660">}</span><span style=3D"color:#000"><br><br></span><span style=3D"=
color:#008">void</span><span style=3D"color:#000"> foo</span><span style=3D=
"color:#660">(</span><span style=3D"color:#000">X</span><span style=3D"colo=
r:#660">&amp;</span><span style=3D"color:#000"> stored</span><span style=3D=
"color:#660">)</span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#800">//free of cost</span><span style=3D"color:#000"><br></span><span st=
yle=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 stored</sp=
an><span style=3D"color:#660">.</span><span style=3D"color:#000">bar</span>=
<span style=3D"color:#660">();</span><span style=3D"color:#000"><br></span>=
<span style=3D"color:#660">}</span><span style=3D"color:#000"><br><br></spa=
n><span style=3D"color:#008">int</span><span style=3D"color:#000"> main</sp=
an><span style=3D"color:#660">()</span><span style=3D"color:#000"><br></spa=
n><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =
foo</span><span style=3D"color:#660">(</span><span style=3D"color:#000">ini=
t</span><span style=3D"color:#660">());</span><span style=3D"color:#000"> <=
/span><span style=3D"color:#800">//only main pay cost of init</span><span s=
tyle=3D"color:#000"><br></span><span style=3D"color:#660">}</span><span sty=
le=3D"color:#000"><br><br></span><span style=3D"color:#008">auto</span><spa=
n style=3D"color:#660">&amp;</span><span style=3D"color:#000"> global_x </s=
pan><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> init</=
span><span style=3D"color:#660">();</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#800">//this could work too</span><span style=3D"col=
or:#000"><br></span></div></code></div><br><br></div><div>=C2=A0</div><bloc=
kquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-lef=
t:1px #ccc solid;padding-left:1ex"><div class=3D"gmail_quote"><div dir=3D"l=
tr">On Thu, Oct 4, 2018 at 8:35 PM Matthew Fioravante &lt;<a rel=3D"nofollo=
w">fmatth...@gmail.com</a>&gt; wrote:<br></div><blockquote class=3D"gmail_q=
uote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1e=
x"><div dir=3D"ltr"><div>One big area where dynamic languages are way ahead=
 of C++ is runtime dynamic code generation or self modifying code.<br></div=
><div><br></div><div><br></div><div>One tiny example is singleton initializ=
ation. The only safe way in C++ to do non-constexpr singletons is by lazy i=
nit. <br></div><div><br></div><div>The problem with lazy init is that you h=
ave to pay for a branch on every access, and that usually involves an atomi=
c check.</div><div><br></div><div>What if you instead you atomically overwr=
ote the check with NOPS. Then the branch is gone and accessing the object i=
s as efficient as if it weren&#39;t lazy.<br></div><div><br></div><div>Has =
anyone considered writing proposals for improving runtime code gen with C++=
?<br></div></div>

<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a rel=3D"nofollow">std-proposal...@isocpp.org</a>.<br>
To post to this group, send email to <a rel=3D"nofollow">std-pr...@isocpp.o=
rg</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/4489f889-977c-45f2-8a2f-186ee3b06bff%=
40isocpp.org?utm_medium=3Demail&amp;utm_source=3Dfooter" rel=3D"nofollow" t=
arget=3D"_blank" onmousedown=3D"this.href=3D&#39;https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/4489f889-977c-45f2-8a2f-186ee3b06bff%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" on=
click=3D"this.href=3D&#39;https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/4489f889-977c-45f2-8a2f-186ee3b06bff%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/4489f889-977c-45f2-<wbr>8a2f-=
186ee3b06bff%40isocpp.org</a><wbr>.<br>
</blockquote></div>
</blockquote></div></blockquote></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; 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/649745f6-d2ff-4a01-bb51-964ba48ea1ee%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/649745f6-d2ff-4a01-bb51-964ba48ea1ee=
%40isocpp.org</a>.<br />

------=_Part_1229_1584657147.1538850135224--

------=_Part_1228_402401588.1538850135223--

.