220 31422 <113327fb-b26a-421e-9b07-9a2045c4178f@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Bengt Gustafsson <bengt.gustafsson@beamways.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Re: P0534: call/cc, type safety and exceptions
Date: Sat, 4 Mar 2017 11:04:15 -0800 (PST)
Lines: 456
Approved: news@gmane.org
Message-ID: <113327fb-b26a-421e-9b07-9a2045c4178f@isocpp.org>
References: <fc546ea4-a355-4a60-a7e7-97927993471d@isocpp.org>
 <3a57e294-7254-4358-828d-c9f7757f5295@isocpp.org> <4e6c13b2-4286-4df8-989b-97cbf3bf1cc7@isocpp.org>
 <312d04a6-8b20-4bf5-8357-507ba9938e84@isocpp.org> <a3c76a9f-ef02-4ea7-a754-66ee5a95b38f@isocpp.org>
 <762243ed-0c31-461d-b6fd-fdb8759857b2@isocpp.org> <f8a573b1-c4ff-48a2-8a6f-51433732ab26@isocpp.org>
 <aecc5a06-78cc-4071-8cce-b2e731439463@isocpp.org> <bc17b8b0-6e62-4e75-b271-7a744c57ea04@isocpp.org>
 <CA+wfc1-Pd3iR+xBeqDc4AZ_BpPFJRJw5grusofJaY8UuUnvEcA@mail.gmail.com> <33bda80d-c83a-4cb9-a67f-5c7b2658e060@isocpp.org>
 <CA+wfc1_jk4zFYjr4nrvFzhN6RY9XrfSipVPEwPfSRbY8hMQJzg@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_1214_2074571044.1488654255895"
X-Trace: blaine.gmane.org 1488654264 8617 195.159.176.226 (4 Mar 2017 19:04:24 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sat, 4 Mar 2017 19:04:24 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCRIRSPDTQIRBMM75TCQKGQEQF65QTQ@isocpp.org Sat Mar 04 20:04:17 2017
Return-path: <std-proposals+bncBCRIRSPDTQIRBMM75TCQKGQEQF65QTQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pf0-f200.google.com ([209.85.192.200])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCRIRSPDTQIRBMM75TCQKGQEQF65QTQ@isocpp.org>)
	id 1ckEyS-0000yM-Cd
	for gclcip-std-proposals@m.gmane.org; Sat, 04 Mar 2017 20:04:12 +0100
Original-Received: by mail-pf0-f200.google.com with SMTP id l66sf46467547pfl.6
        for <gclcip-std-proposals@m.gmane.org>; Sat, 04 Mar 2017 11:04:18 -0800 (PST)
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
         :x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=gX7zL3g1zMv2h3EcawMsrGn0aZCSBVC62oN5fDe8gUE=;
        b=HpDXvLCecv/P5gvHnTEADMOIdwhm7YZq4LFMgzF2Q8mQL2VZUTpx7Rir7Uce+uCEAb
         +MPg1Tsw1yIeqykrNdGJ0SfIowZ6S7JiGB7WTanbjwtas8c//tyKOpcV2bOYxqXI0zo0
         tDEqOtFcKJw9c6KwzfZXVEbNCSAwXNERuDopIDyVKB5XBrMFSfSovdUxynYdpicRAgUB
         aZInnMNLJJJHmR/6UCJS0A45P/43iWJBCkNCMiq1/9b20gONvf+4Mn/FMDx8Mv0EzEmd
         4ELvAX0JvoJY3DUnmL54RpAUp7/rCG2j3FbHet0lUjeY8WsEt1vnbZEvXDOkToNaBrjJ
         rdhg==
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=gX7zL3g1zMv2h3EcawMsrGn0aZCSBVC62oN5fDe8gUE=;
        b=TNMz4FTPdhj5lFoK8PKTvALa8Jgor8PFtn+okoI7KuFFE4JAKr/5RXoJ1R/FAXX+Hb
         EiDCLSzcrlzBQnGgmstGnb6vtjUTmhL4tWI3M43lCLKfbxOm05Iie9meUyFey1OUdN3a
         YN+IHts8DWeyPoY8qQTosKKMKs4mGt/xUCIpKFvB8VWw0dTmSGTNSdSGQSwtTGVtZwVh
         +cOKN/9LX5YR0MWnmYDO0NTxxd4qntcYKGl9CVtfhfjZrKf906fL4WU7Dt6kytwN+z2p
         kS0A/vLgooxwyo0pnHwBqUR89GMCVDG2mT6DCIe+n2XRuDb1pYv9Fv0UxLm4E0o4AHSP
         Swfw==
X-Gm-Message-State: AMke39nFQ0AOvdNzZsSCoad8AuYHUreooz3pXwH8bnZEQ4iCP+fb6hHg7hz8YSkewQoleg==
X-Received: by 10.99.122.70 with SMTP id j6mr3414647pgn.89.1488654258120;
        Sat, 04 Mar 2017 11:04:18 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.157.27.71 with SMTP id l65ls11718861otl.41.gmail; Sat, 04 Mar
 2017 11:04:16 -0800 (PST)
X-Received: by 10.157.16.48 with SMTP id h45mr855735ote.10.1488654256928;
        Sat, 04 Mar 2017 11:04:16 -0800 (PST)
In-Reply-To: <CA+wfc1_jk4zFYjr4nrvFzhN6RY9XrfSipVPEwPfSRbY8hMQJzg@mail.gmail.com>
X-Original-Sender: bengt.gustafsson@beamways.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <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:31422
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/31422>

------=_Part_1214_2074571044.1488654255895
Content-Type: multipart/alternative; 
	boundary="----=_Part_1215_1050567901.1488654255896"

------=_Part_1215_1050567901.1488654255896
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable



Den l=C3=B6rdag 4 mars 2017 kl. 17:14:18 UTC+1 skrev Oliver Kowalke:
>
> 2017-03-04 15:27 GMT+01:00 Bengt Gustafsson <bengt.gu...@beamways.com=20
> <javascript:>>:
>
>>
>>> But I don't understand the need of data transfer at this low abstractio=
n=20
>>>> level. After all, these are not threads, so there is no asynchronism t=
o=20
>>>> think about.=20
>>>>
>>>
>>> P0534 is symmetric context switching, e.g. no coupling between caller=
=20
>>> and callee as it is for generators/coroutines.
>>>
>> Exactly, that's why I asked why data transfer is needed _on the call/cc=
=20
>> level_. I showed in my example that you can do data transfer on top of t=
his=20
>> (at the generator level) with essentially no overhead. Giovanni pointed =
out=20
>> that there may be the overhead of one register save/restore, and if this=
=20
>> the performance gain you are after I think the price of a scary "void*"=
=20
>> style interface (hidden behind an unsafe cast) is not worth it, and if t=
he=20
>> access is to be tested the performance cost is definitely more than a=20
>> register save.
>>
>
> I don't see your point - accessing a register if verry fast (1 CPU cycle =
I=20
> guess).
>
The point is that if the feature does not have a large performance gain=20
compared to not having it, and if it does not avoid a complex=20
synchronization problem then why have it? I don't see that you have shown=
=20
any major performance or synchronization gain.

=20

> The data transfer as proposed in P0534 (and used for coroutine and fiber=
=20
> implementation) does provide some kind of type-safety and no overhead if =
no=20
> data are transferred.
>
While ideas in the direction of my Generator class offers compile time type=
=20
safety and negligable overhead even if used! Not to mention a smaller API.
=20

> =20
>
>>  And you don't know the identity of the continuation returned from=20
>> operator() in your case, what is the difference? The advantage of the in=
=20
>> situ version is however obvious: You can't forget doing the assignment, =
and=20
>> thereby leave the continuation object stale.=20
>>
>
> Suppose you have contoinuations c1, c2:
>
> c1 =3D callcc( foo);
> c2 =3D callcc( bar);
>
> - in main() you resume c1: c1();
>
This must mean that both foo and bar have transfered control back to main=
=20
which in some later code calls c1().

> - c1 executes foo
>
continuing foo after its first context switch.=20
=20
=20

> - in foo you resume c2: c2()
>
ok, a bit odd but doable.=20

- c2 executes bar
>
continuing bar after its first context switch.
=20

> - in bar you jump to main()
>
Unless you involve setjmp/longjmp I don't see a way fot this to happen...=
=20
and those guys are not C++ safe anyway. What can happen is that foo gives=
=20
bar access to its stored continuation and bar uses this to transfer control=
=20
to main after its c1() call.
And sure enough c1 now refers to bar after its second context switch. Yes=
=20
this seems to be what you refer to.
=20

> - that means you return from c1() in main()
> - if you call c1() in main() you do resume bar() instead of foo()
>
Yes. This can happen if you store the continuations in global variables=20
where other functions can reach them. Isn't this why we want to abstract=20
the continuation level into higher level abstractions which are easier to=
=20
understand and where these types of
oddities are easy to avoid.

The only gain with the assignment is as a reminder of "next time this=20
continuation will continue executing somewhere else". But as that always=20
happens and you can not make something else happen by NOT doing the=20
assignment (except dropping a valuable asset) it seems rather error prone..=
..


> =20
>
>>
>>> =20
>>>
>>>> Also it would be interesting to know when this rather strange=20
>>>> functionality is useful.
>>>>
>>>
>>> described in P0534:
>>> you can invoke a new function after resuming the context that throws an=
=20
>>> exception
>>>
>> =20
>> It is a bit hard to understsand this sentense.=20
>>
>
> context switching is a bit mind twisiting
> =20
>
>> Do you mean to resume a context after it has thrown an exception?=20
>>
>
> no - resume the context and then, if you are in the resumed context,=20
> create a new stack frame and execute your supplied function (that might=
=20
> throw)=20
>
OK, I understand what it does, my question was why this is useful.=20

> =20
>
>> =20
>>
>>> for instance you want abort and unwind the stack - instead to check for=
=20
>>> abort each time the context is resumed you call invoke-ontop=20
>>> functionality to execute the throwing abort function only at the time p=
oint=20
>>> you know you want to abort the continuation/context
>>>
>> I think you may be saying that once in a while one party injects code=20
>> that throws if an abort flag is set into another piece of code on the ot=
her=20
>> side of the continuation.=20
>>
>
> yes
> =20
>
>> Or maybe you test the abort flag first and then injects a function which=
=20
>> just throws an exception. Well that would be a way to get rid of the=20
>> continuation and properly unwind its stack, but didn't you have a specif=
ic=20
>> way of doing that, such as desrtroying the continuation object?
>>
>
> throwing an exeception was only one use case - infact if a suspended=20
> continuation has to be destroyed (instance goes out of scope) out of a de=
ep=20
> callstack - the current implementation executes a function ontop of those=
=20
> continuation that throws a speciall exception that unwinds the stakc of t=
he=20
> continuation and jumps back to the caller.
>
Yes, that is how I understood it. This is what would happen if you forget=
=20
to assign the returned continuation to your variable, I assume ;-)

So the only use case for invoke_on_top() that you have produced is in fact=
=20
equivalent to destroying the continuation object. Given that you can't=20
access data in underlying stack frames I fail to see a difference between=
=20
these two:

continuation c;

fun()
c()

and
c.invoke_on_top(fun);

Well, there may be some difference if fun throws, but isn't it unlikely=20
that the code dormant in c would have suitable catch clauses for throws in=
=20
an unrelated function fun.

Ok, maybe you only see this as a method of throwing an exception in the=20
other stack, if so maybe it would be better to have an explicit mechanism=
=20
for this:

template<typename EX, typename.... Args> continuation::throw_in(Args...);

This just swaps the stacks and then executes `throw EX(args...)`

The advantage of this approach is that it is obvious what it does and it=20
does not invite to inject arbitrary function calls (which may throw=20
exceptions without catching them) onto some other stack not prepared for=20
this.,

I would have thought that the main use would be to allow a pool of fibers=
=20
to be used for executing arbitrary code. The main reason for not doing new=
=20
callcc() calls each time would be to avoid having to allocate stacks each=
=20
time. If this is the use case it seems that the stack rather than the=20
continuation is the object to preserve and pool. It may be that this is the=
=20
functionality Nicol was asking for.
=20

> =20
>

--=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/113327fb-b26a-421e-9b07-9a2045c4178f%40isocpp.or=
g.

------=_Part_1215_1050567901.1488654255896
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>Den l=C3=B6rdag 4 mars 2017 kl. 17:14:18 UTC+1 skr=
ev Oliver Kowalke:<blockquote class=3D"gmail_quote" style=3D"margin: 0;marg=
in-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"=
ltr"><div><div class=3D"gmail_quote">2017-03-04 15:27 GMT+01:00 Bengt Gusta=
fsson <span dir=3D"ltr">&lt;<a href=3D"javascript:" target=3D"_blank" gdf-o=
bfuscated-mailto=3D"vgzdgWShCgAJ" rel=3D"nofollow" onmousedown=3D"this.href=
=3D&#39;javascript:&#39;;return true;" onclick=3D"this.href=3D&#39;javascri=
pt:&#39;;return true;">bengt.gu...@beamways.com</a><wbr>&gt;</span>:<br><bl=
ockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-lef=
t:1px solid rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr"><blockquote=
 class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px so=
lid rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr"><div><div class=3D"=
gmail_quote"><span><br><blockquote style=3D"margin:0px 0px 0px 0.8ex;border=
-left:1px solid rgb(204,204,204);padding-left:1ex" class=3D"gmail_quote"><d=
iv dir=3D"ltr">But I don&#39;t understand the need of data transfer at this=
 low abstraction level. After all, these are not threads, so there is no as=
ynchronism to think about. <br></div></blockquote><div><br></div></span><di=
v>P0534 is symmetric context switching, e.g. no coupling between caller and=
 <span>callee</span> as it is for generators/<span>coroutines.</span></div>=
</div></div></div></blockquote><div>Exactly, that&#39;s why I asked why dat=
a transfer is needed _on the call/cc level_. I showed in my example that yo=
u can do data transfer on top of this (at the generator level) with essenti=
ally no overhead. Giovanni pointed out that there may be the overhead of on=
e register save/restore, and if this the performance gain you are after I t=
hink the price of a scary &quot;void*&quot; style interface (hidden behind =
an unsafe cast) is not worth it, and if the access is to be tested the perf=
ormance cost is definitely more than a register save.</div></div></blockquo=
te><div><br></div><div>I don&#39;t see your point - accessing a register if=
 verry fast (1 CPU cycle I guess).<br></div></div></div></div></blockquote>=
<div>The point is that if the feature does not have a large performance gai=
n compared to not having it, and if it does not avoid a complex synchroniza=
tion problem then why have it? I don&#39;t see that you have shown any majo=
r performance or synchronization gain.</div><div><br></div><div>=C2=A0</div=
><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bo=
rder-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div><div cl=
ass=3D"gmail_quote"><div></div><div>The data transfer as proposed in P0534 =
(and used for coroutine and fiber implementation) does provide some kind of=
 type-safety and no overhead if no data are transferred.</div></div></div><=
/div></blockquote><div>While ideas in the direction of my Generator class o=
ffers compile time type safety and negligable overhead even if used! Not to=
 mention a smaller API.</div><div>=C2=A0</div><blockquote class=3D"gmail_qu=
ote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padd=
ing-left: 1ex;"><div dir=3D"ltr"><div><div class=3D"gmail_quote"><div>=C2=
=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8e=
x;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr"=
><span><div>=C2=A0And you don&#39;t know the identity of the continuation r=
eturned from operator() in your case, what is the difference? The advantage=
 of the in situ version is however obvious: You can&#39;t forget doing the =
assignment, and thereby leave the continuation object stale.=C2=A0</div></s=
pan></div></blockquote><div><br></div><div>Suppose you have contoinuations =
c1, c2:<br><br></div><div>c1 =3D callcc( foo);<br>c2 =3D callcc( bar);</div=
><div><br></div><div>- in main() you resume c1: c1();<br></div></div></div>=
</div></blockquote><div>This must mean that both foo and bar have transfere=
d control back to main which in some later code calls c1().</div><blockquot=
e class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: =
1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div><div class=3D"gmai=
l_quote"><div>- c1 executes foo<br></div></div></div></div></blockquote><di=
v>continuing foo after its first context switch.=C2=A0</div><div>=C2=A0</di=
v><div>=C2=A0</div><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"><div><div class=3D"gmail_quote"><div></div><div>- in foo you resume c=
2: c2()<br></div></div></div></div></blockquote><div>ok, a bit odd but doab=
le.=C2=A0</div><div><br></div><blockquote class=3D"gmail_quote" style=3D"ma=
rgin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">=
<div dir=3D"ltr"><div><div class=3D"gmail_quote"><div></div><div>- c2 execu=
tes bar<br></div></div></div></div></blockquote><div>continuing bar after i=
ts first context switch.</div><div>=C2=A0</div><blockquote class=3D"gmail_q=
uote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;pad=
ding-left: 1ex;"><div dir=3D"ltr"><div><div class=3D"gmail_quote"><div></di=
v><div>- in bar you jump to main()<br></div></div></div></div></blockquote>=
<div>Unless you involve setjmp/longjmp I don&#39;t see a way fot this to ha=
ppen... and those guys are not C++ safe anyway. What can happen is that foo=
 gives bar access to its stored continuation and bar uses this to transfer =
control to main after its c1() call.</div><div>And sure enough c1 now refer=
s to bar after its second context switch. Yes this seems to be what you ref=
er to.</div><div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"mar=
gin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><=
div dir=3D"ltr"><div><div class=3D"gmail_quote"><div></div><div>- that mean=
s you return from c1() in main()<br></div><div>- if you call c1() in main()=
 you do resume bar() instead of foo()<br></div></div></div></div></blockquo=
te><div>Yes. This can happen if you store the continuations in global varia=
bles where other functions can reach them. Isn&#39;t this why we want to ab=
stract the continuation level into higher level abstractions which are easi=
er to understand and where these types of</div><div>oddities are easy to av=
oid.</div><div><br></div><div>The only gain with the assignment is as a rem=
inder of &quot;next time this continuation will continue executing somewher=
e else&quot;. But as that always happens and you can not make something els=
e happen by NOT doing the assignment (except dropping a valuable asset) it =
seems rather error prone...</div><div><br></div><blockquote class=3D"gmail_=
quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;pa=
dding-left: 1ex;"><div dir=3D"ltr"><div><div class=3D"gmail_quote"><div><br=
></div><div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0=
px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><=
div dir=3D"ltr"><span><blockquote class=3D"gmail_quote" style=3D"margin:0px=
 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><di=
v dir=3D"ltr"><div><div class=3D"gmail_quote"><div></div><div><br></div><di=
v>=C2=A0</div><blockquote style=3D"margin:0px 0px 0px 0.8ex;border-left:1px=
 solid rgb(204,204,204);padding-left:1ex" class=3D"gmail_quote"><div dir=3D=
"ltr"><div>Also it would be interesting to know when this rather strange fu=
nctionality is useful.</div></div></blockquote><div><br></div><div>describe=
d in P0534:<br></div><div>you can invoke a new function after resuming the =
context that throws an exception<br></div></div></div></div></blockquote><d=
iv>=C2=A0</div></span><div>It is a bit hard to understsand this sentense. <=
/div></div></blockquote><div><br></div><div>context switching is a bit mind=
 twisiting<br></div><div>=C2=A0</div><blockquote class=3D"gmail_quote" styl=
e=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);paddin=
g-left:1ex"><div dir=3D"ltr"><div>Do you mean to resume a context after it =
has thrown an exception? </div></div></blockquote><div><br></div><div>no - =
resume the context and then, if you are in the resumed context, create a ne=
w stack frame and execute your supplied function (that might throw) <br></d=
iv></div></div></div></blockquote><div>OK, I understand what it does, my qu=
estion was why this is useful.=C2=A0</div><blockquote class=3D"gmail_quote"=
 style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-=
left: 1ex;"><div dir=3D"ltr"><div><div class=3D"gmail_quote"><div></div><di=
v>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px=
 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir=3D=
"ltr"><span><div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"mar=
gin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1=
ex"><div dir=3D"ltr"><div><div class=3D"gmail_quote"><div></div><div>for in=
stance you want abort <span>and</span> unwind the stack - instead to check =
for abort each time the context is resumed you call invoke-<span>ontop</spa=
n> functionality to execute the throwing abort function only at the time po=
int you know you want to abort the continuation/context<br></div></div></di=
v></div></blockquote></span><div>I think you may be saying that once in a w=
hile one party injects code that throws if an abort flag is set into anothe=
r piece of code on the other side of the continuation. </div></div></blockq=
uote><div><br></div><div>yes<br></div><div>=C2=A0</div><blockquote class=3D=
"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(2=
04,204,204);padding-left:1ex"><div dir=3D"ltr"><div>Or maybe you test the a=
bort flag first and then injects a function which just throws an exception.=
 Well that would be a way to get rid of the continuation and properly unwin=
d its stack, but didn&#39;t you have a specific way of doing that, such as =
desrtroying the continuation object?</div></div></blockquote><div><br></div=
><div>throwing an exeception was only one use case - infact if a suspended =
continuation has to be destroyed (instance goes out of scope) out of a deep=
 callstack - the current implementation executes a function ontop of those =
continuation that throws a speciall exception that unwinds the stakc of the=
 continuation and jumps back to the caller.<br></div></div></div></div></bl=
ockquote><div>Yes, that is how I understood it. This is what would happen i=
f you forget to assign the returned continuation to your variable, I assume=
 ;-)</div><div><br></div><div>So the only use case for invoke_on_top() that=
 you have produced is in fact equivalent to destroying the continuation obj=
ect. Given that you can&#39;t access data in underlying stack frames I fail=
 to see a difference between these two:</div><div><br></div><div>continuati=
on c;</div><div><br></div><div>fun()</div><div>c()</div><div><br></div><div=
>and</div><div>c.invoke_on_top(fun);</div><div><br></div><div>Well, there m=
ay be some difference if fun throws, but isn&#39;t it unlikely that the cod=
e dormant in c would have suitable catch clauses for throws in an unrelated=
 function fun.</div><div><br></div><div>Ok, maybe you only see this as a me=
thod of throwing an exception in the other stack, if so maybe it would be b=
etter to have an explicit mechanism for this:</div><div><br></div><div>temp=
late&lt;typename EX, typename.... Args&gt; continuation::throw_in(Args...);=
</div><div><br></div><div>This just swaps the stacks and then executes `thr=
ow EX(args...)`</div><div><br></div><div>The advantage of this approach is =
that it is obvious what it does and it does not invite to inject arbitrary =
function calls (which may throw exceptions without catching them) onto some=
 other stack not prepared for this.,</div><div><br></div><div>I would have =
thought that the main use would be to allow a pool of fibers to be used for=
 executing arbitrary code. The main reason for not doing new callcc() calls=
 each time would be to avoid having to allocate stacks each time. If this i=
s the use case it seems that the stack rather than the continuation is the =
object to preserve and pool. It may be that this is the functionality Nicol=
 was asking for.</div><div>=C2=A0</div><blockquote class=3D"gmail_quote" st=
yle=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-lef=
t: 1ex;"><div dir=3D"ltr"><div><div class=3D"gmail_quote"><div></div><div>=
=C2=A0<br></div></div></div></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/113327fb-b26a-421e-9b07-9a2045c4178f%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/113327fb-b26a-421e-9b07-9a2045c4178f=
%40isocpp.org</a>.<br />

------=_Part_1215_1050567901.1488654255896--

------=_Part_1214_2074571044.1488654255895--

.
