220 40349 <649745f6-d2ff-4a01-bb51-964ba48ea1ee@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: inkwizytoryankes@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Runtime code generation and self modifying code
Date: Sat, 6 Oct 2018 11:22:15 -0700 (PDT)
Lines: 322
Approved: news@gmane.org
Message-ID: <649745f6-d2ff-4a01-bb51-964ba48ea1ee@isocpp.org>
References: <4489f889-977c-45f2-8a2f-186ee3b06bff@isocpp.org>
 <CAMD6iD_1Xqqa7Qjv35FaCH1Q39Jitr8Okwds-_2i0wWxz6EEYA@mail.gmail.com>
 <4503e7f2-de35-413f-a0d6-3d637c0609e9@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_1228_402401588.1538850135223"
X-Trace: blaine.gmane.org 1538850011 3405 195.159.176.226 (6 Oct 2018 18:20:11 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sat, 6 Oct 2018 18:20:11 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDDLTAGNTIBBBWH24POQKGQEGDCE4FA@isocpp.org Sat Oct 06 20:20:07 2018
Return-path: <std-proposals+bncBDDLTAGNTIBBBWH24POQKGQEGDCE4FA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yw1-f70.google.com ([209.85.161.70])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDDLTAGNTIBBBWH24POQKGQEGDCE4FA@isocpp.org>)
	id 1g8rBP-0000lQ-Eg
	for gclcip-std-proposals@m.gmane.org; Sat, 06 Oct 2018 20:20:07 +0200
Original-Received: by mail-yw1-f70.google.com with SMTP id i1-v6sf9950971ywd.4
        for <gclcip-std-proposals@m.gmane.org>; Sat, 06 Oct 2018 11:22:17 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=eTHsQhGzT5p+PaQxPvAHMnb8eEuB+kHbTpoKgw2P2AQ=;
        b=oL/dbWoecMWLFHs0F6/AQH2/mP1rVxx6kI0H9G+Pn6JsFhxJ4oQB/XM5f7TzMnbrGy
         IFP7nNanY4um9o+KNBzJXqW27dFlAfvRnGIKoTyb3v4lUwIzWOzWU4g9tRRBK4FQWzuM
         WAfrOl5pDiDswytVrD3n76XAQ278UZwe+IUXmjmViLjEkvy8qjrTomFEkwZV1EWFXBhZ
         L2wjcMgdk1v2ga20GntYR7/Tbx0cpYKK8gDqTU3rYOpjHwXpuaJN2+duyxfvK73IDN51
         kU0VUuLx687+180ASZFUpFzzV2RBxm/dj2KLZRNsGfhL7QoBc4r7BB02oC+mNfQ3tizp
         x8jQ==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=eTHsQhGzT5p+PaQxPvAHMnb8eEuB+kHbTpoKgw2P2AQ=;
        b=JRZ91VVON0kRm2gWIfTEmW5PZmSOwWJR6aSvf2LM7FGBlmR7X6yLcyJIqnM5D3i1zD
         te+iUU6Jo4A6PCsGG0vbtlw9Om2Krl9BXLvdQHqaUJxUeCv6lY28wZdDx+5R9b9ogSEH
         T62eqyfNDcFzvB7vgDrCbFEyJgWPc34fNunGjHUheet0Lqcej794VILdY3fzKF2dOXbg
         4+Ff6rvnNoU/p9d3jLSEgnHMj1QP7/lGqe2Y3nZjTNg4ABCGyBPQF9VUSSioiq5uljXj
         jh9XvKvlwmazI3ApOzGw4iPTQ3+9bR7utKMtzgWLnZlFgsaFULx671RaMS3u5yYlUk1O
         0mPw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:x-original-sender:reply-to:precedence
         :mailing-list:list-id:x-spam-checked-in-group:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=eTHsQhGzT5p+PaQxPvAHMnb8eEuB+kHbTpoKgw2P2AQ=;
        b=rFNWmMT2dNNege3/GWKPAliEG+Q3QrRYjkOeMJLVzOxLuOua+tGj8pjas+My+oCbL8
         KNA/TNicQiNtmz8TZjSY5k6wZGXzijA6Cn+NwWiMyncBBlo5mislbaLEYWIpsoEH8ed5
         uBUulRZXzNJVS8ZzSMte3oogsh/9EnmIE9hjHHg2NESSsl2sCivq60a4gvz02RcZD4SM
         UGc2cyaPk3KuahGHDZcNw1chuA9OhkTsBBKljQdpAviUGV7j6MdECTOobOLvhNf6IC/P
         H9RJDg/2ZL9q5v/xqQ7ir6WfKcH1v28nRPdmmRgjK6pyiEQ18gQMcTy5AOxwi4IfaOQF
         B3yw==
X-Gm-Message-State: ABuFfoiZ15JL+QhGl0rNY5synnrpSbzAjR0TdeU50h7iKkzsM3jtTrDx
	XJ7GIZmXI+Ee4UNjryghkKhfhQ==
X-Google-Smtp-Source: ACcGV62S7h2T2ZSXbtd3/86gPUNLr4qMyNwtpTUjxxrC8+L++YRtZKhGr90bruyn3PoJ0vYUcfBniw==
X-Received: by 2002:a25:a091:: with SMTP id y17-v6mr9976435ybh.53.1538850137323;
        Sat, 06 Oct 2018 11:22:17 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 2002:a81:ae21:: with SMTP id m33-v6ls2566863ywh.9.gmail; Sat, 06
 Oct 2018 11:22:15 -0700 (PDT)
X-Received: by 2002:a81:13d4:: with SMTP id 203-v6mr135201ywt.5.1538850135673;
        Sat, 06 Oct 2018 11:22:15 -0700 (PDT)
In-Reply-To: <4503e7f2-de35-413f-a0d6-3d637c0609e9@isocpp.org>
X-Original-Sender: inkwizytoryankes@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: std-proposals@isocpp.org
X-Google-Group-Id: 399137483710
List-Post: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:40349
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/40349>

------=_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--

.
