220 21926 <e9b4c568-2a00-4f25-8324-921ca1926abe@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Giovanni Piero Deretta <gpderetta@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: is await an extension of the do-notation? (was Re:
 Re: Resumable expressions p0114r0 vs async/await P0057R0)
Date: Wed, 21 Oct 2015 10:15:57 -0700 (PDT)
Lines: 150
Approved: news@gmane.org
Message-ID: <e9b4c568-2a00-4f25-8324-921ca1926abe@isocpp.org>
References: <639f0012-8cb4-4db3-82a6-8d042a3497f9@isocpp.org>
 <401aa118-ed0b-4c7b-92cf-3fbd706eff9d@isocpp.org> <fcbcc1c4-535c-4fa2-a17d-4acffe84a4b5@isocpp.org>
 <1d15dbc4-e0c1-4df1-86db-014e11f14d26@isocpp.org> <56114953.4030701@wanadoo.fr>
 <561B403D.4030403@gmail.com> <CAOfiQqkKvZfVatJ1Bz4qSvGc-g6iep0xeP1B1=J1-gCu43NXxg@mail.gmail.com>
 <561C07D1.3080304@gmail.com> <CAOfiQqnR4GYCttwu8G-44_UEN4WekW19uorEvf-5VC3vOpej-g@mail.gmail.com>
 <561C213F.1060009@gmail.com> <fb82d876-8a54-4c28-8e53-297018470cf6@isocpp.org>
 <561C3875.2050701@gmail.com> <86924069-44d0-447f-bf8a-a42e46579832@isocpp.org>
 <561D79A7.8080007@gmail.com> <894616d6-9609-4038-b2bc-d2c62df21e0f@isocpp.org>
 <99bdb3ae-9214-4440-8572-4c47a61eda46@isocpp.org> <58628096-14ae-42b2-89d3-c0bd2183bbc0@isocpp.org>
 <561DC957.8080603@gmail.com> <a44dae17-5f63-4c60-a943-d74a1332b54c@isocpp.org>
 <d3723a3d-1b73-4c6c-bc7f-3d224d2ec8a2@isocpp.org> <2e09660f-d688-474a-8811-85fb041f68b8@isocpp.org>
 <f3dbc6ee-80cf-43f1-9b49-7ed1879de0cc@isocpp.org> <8b78abb4-16b6-4b65-8513-6e2c17317647@isocpp.org>
 <CAL52AasThHcBZUbyT1NfgzEe+qaWKuO9eE6pxS-qfXxxSSbcbQ@mail.gmail.com>
 <779be861-3b2a-427a-b36b-ad2874c81129@isocpp.org> <CAL52AasaxsP2i-Bh-kVrCoKad_Z08dUpL-0w=Lb2dyTGz3f9PQ@mail.gmail.com>
 <767364f8-785d-4f8f-9bc0-852df56ee4eb@isocpp.org> <f27fd4c9-86c4-44a7-8162-991a32a38e63@isocpp.org>
 <CA+wfc1-qmKY-yA1fPOmWjGuR7qTMY3PRVbjxtPaPn2FLad2hBA@mail.gmail.com>
 <d7653631-b45c-4952-a308-9919e84c538e@isocpp.org> <CA+wfc1-s0_TZUn_FcoPnEFTOiofM8oLwdy_4EWDmtK+wApratw@mail.gmail.com>
 <f03a6bdc-6719-4f4a-bcff-e39d819e2eff@isocpp.org> <CA+wfc1_16+NXesmOFUrOJpPa=X+RGm0Rr89CTe1mGFWK8JUAiA@mail.gmail.com>
 <0a728eee-e8e7-48ea-adf6-2a8dae63916e@isocpp.org>
 <CA+wfc1-b_TaJT-FQmZ3hEYzH+B16CaqcBd4wbgmf84gagegHYw@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_4609_210998052.1445447757761"
X-Trace: ger.gmane.org 1445447775 20705 80.91.229.3 (21 Oct 2015 17:16:15 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 21 Oct 2015 17:16:15 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDEP3I7TGEIM5EE7WECRUBEHAPPAC@isocpp.org Wed Oct 21 19:16:11 2015
Return-path: <std-proposals+bncBDEP3I7TGEIM5EE7WECRUBEHAPPAC@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-vk0-f70.google.com ([209.85.213.70])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDEP3I7TGEIM5EE7WECRUBEHAPPAC@isocpp.org>)
	id 1Zowzd-0001rE-JW
	for gclcip-std-proposals@m.gmane.org; Wed, 21 Oct 2015 19:16:05 +0200
Original-Received: by vkfw189 with SMTP id w189sf81034368vkf.1
        for <gclcip-std-proposals@m.gmane.org>; Wed, 21 Oct 2015 10:15:59 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :content-type: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=3Q3g1NTBTUzNqD1WLJFbUD5gz/OyxzRgMoAJixyt2wo=;
        b=qjQvtEsrD5Fkw8i2t0AKUlSnexopeYIyU0HOJqzUcn972rvDDWtJJPMyUEHYVlj8gk
         7SH5LviVgGaDEZNz2Jl5q0kFrCDO6iD8185hYXtWyQquLSEuBmcpY4nbJBKFJtNSHfGO
         d9KBpk+jZ2TU2af1+Dq/4vIscZ3UR4kX90VhLbsGaHEhg6QUriqg/7Yt9Hkc5sZRavGZ
         qZTnjfwA0jGbqOSGGnkXRBpvo8wVmHmJyQj+cRZLwdkMhiBKARapYLj/8e2jzfwqIEsE
         IG7ssQd7LKWloE9r5spuGbrsmTvjXXWWshalay4is2S8bxPyROxXRZbO49xDf5ARdhlD
         9CuQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:content-type: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=3Q3g1NTBTUzNqD1WLJFbUD5gz/OyxzRgMoAJixyt2wo=;
        b=g4uus5edMXPGhKnDq/yBpkVyb2Cti5CCda9qCGz1+SSbYQb+jvTf8RRxPBBxcqnB9Q
         Waxsp+jdvC1qfXj5DXUB3Jvm6+hrGBNEr0WwYJ4ivAODgSfF5GcnmBg7v8Oa29AKZrYW
         Nq8LTtrU5FMRfsL9t73f8Z+oQgcg0xr34EeSSLYFaH+4Vi6xfO1TPfzRytnRuWGTUvSs
         eXbVfBJfd8vImGZaYipIJSeC2OEm8SOXG6Cz9ZLIFPl7i6sG5CVNAuLBMOVfsaiAvUxM
         52yu7lZiq2KsYKEyojlBsu0Mml+A42JH3nAvVcmcWUwvyCSl9OXz7V6mr3t/r7Gbv/Y+
         AEvA==
X-Gm-Message-State: ALoCoQkhIa1noHg5LlCBoovIaZbXa0BVxeCWjbMxd/z5dcI+4KZIopvB00clhoafc43WmMOZsgpk
X-Received: by 10.129.78.205 with SMTP id c196mr8532817ywb.21.1445447759698;
        Wed, 21 Oct 2015 10:15:59 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.78.202 with SMTP id d10ls1583837igx.41.canary; Wed, 21 Oct
 2015 10:15:58 -0700 (PDT)
X-Received: by 10.50.122.103 with SMTP id lr7mr272558igb.10.1445447758834;
        Wed, 21 Oct 2015 10:15:58 -0700 (PDT)
In-Reply-To: <CA+wfc1-b_TaJT-FQmZ3hEYzH+B16CaqcBd4wbgmf84gagegHYw@mail.gmail.com>
X-Original-Sender: gpderetta@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: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://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>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:21926
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/21926>

------=_Part_4609_210998052.1445447757761
Content-Type: multipart/alternative; 
	boundary="----=_Part_4610_1038812166.1445447757761"

------=_Part_4610_1038812166.1445447757761
Content-Type: text/plain; charset=UTF-8

On Wednesday, October 21, 2015 at 5:45:22 PM UTC+1, Oliver Kowalke wrote:
>
> 2015-10-21 15:43 GMT+02:00 Giovanni Piero Deretta <gpde...@gmail.com 
> <javascript:>>:
>
>>
>> Sorry for being dense, this I do not understand. I do not see how one 
>> follows from the other and it doesn't match my experience.
>>
>
> for a context switch you need the current context, which is required to be 
> preserved, and a target context, which has to be resumed
> I thought it is convenient only to know the target context and simply call 
> execution-context::operator() to switch to the target-context.
>

it is very convenient, but it doesn't need to save the current context 
 

>
> it is a small API - one function to resume the context, one function to 
> access the current context
>  
>
>>  callcc is the task switching primitive: it suspend the current thread of 
>> execution and resumes the target one. On the just awakened thread of 
>> execution it returns the just suspened continuation.
>>
>  
> it is not so much different than execution_context of course I could pass 
> the current context through the context switch 
> (execution_context::operator()) to the target context.
> with your callcc the target context always knows its calling context 
> (parent context, what would be the right wording?).
> but in some cases the target context does not need to know from which 
> context it was resumed.
> maybe callcc and execution_context are equivalent
>

With parameter passing they are have equivalent expressibility. It is 
trivial to implement callcc on top of, for example fcontext + parameter 
passing:

Assuming this exists:
void* fcontext_swap (void* p, ctxt*src, ctx*dest);

callcc is equivalent to this:

ctx * callcc(ctx* dst, auto f = [](auto x) {} return x; })
{
     struct data { ctx src; function<ctx*(ctx*)> f } data = { {}, 
std::ref(f) };
     auto * otherdata = (data*)fcontext_swap(&data, &data.src, &dst));
     return otherdata->f(&otherdata->src));
}
     
Although it is not a terribly efficient implementation. Note that the state 
of the context that we are swapping from is saved in a variable local to 
callcc, no need for a global. If the target context doesn't care about the 
src context, the src context can capture and store its own continuation by 
providing 'f' on swap. Again, no need for a global.


-- 

--- 
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_4610_1038812166.1445447757761
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Wednesday, October 21, 2015 at 5:45:22 PM UTC+1, Oliver Kowalke wrote:<b=
lockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;borde=
r-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div><div class=
=3D"gmail_quote">2015-10-21 15:43 GMT+02:00 Giovanni Piero Deretta <span di=
r=3D"ltr">&lt;<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mail=
to=3D"LVAAmT3GEAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;javasc=
ript:&#39;;return true;" onclick=3D"this.href=3D&#39;javascript:&#39;;retur=
n true;">gpde...@gmail.com</a>&gt;</span>:<br><blockquote class=3D"gmail_qu=
ote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex=
"><span></span><br><div>Sorry for being dense, this I do not understand. I =
do not see how one follows from the other and it doesn&#39;t match my exper=
ience.<br></div></blockquote><div><br></div><div>for a context switch you n=
eed the current context, which is required to be preserved, and a target co=
ntext, which has to be resumed<br></div><div>I thought it is convenient onl=
y to know the target context and simply call execution-context::operator() =
to switch to the target-context.<br></div></div></div></div></blockquote><d=
iv><br>it is very convenient, but it doesn&#39;t need to save the current c=
ontext <br>=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 di=
r=3D"ltr"><div><div class=3D"gmail_quote"><div><br></div><div>it is a small=
 API - one function to resume the context, one function to access the curre=
nt context<br></div><div>=C2=A0</div><blockquote class=3D"gmail_quote" styl=
e=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>=
=C2=A0callcc is the task switching primitive: it suspend the current thread=
 of execution and resumes the target one. On the just awakened thread of ex=
ecution it returns the just suspened continuation.<br></div></blockquote><d=
iv>=C2=A0</div></div>it is not so much different than execution_context of =
course I could pass the current context through the context switch (executi=
on_context::operator()<wbr>) to the target context.<br></div><div>with your=
 callcc the target context always knows its calling context (parent context=
, what would be the right wording?).<br></div><div>but in some cases the ta=
rget context does not need to know from which context it was resumed.<br></=
div><div>maybe callcc and execution_context are equivalent<br></div></div><=
/blockquote><div><br>With parameter passing they are have equivalent expres=
sibility. It is trivial to implement callcc on top of, for example fcontext=
 + parameter passing:<br><br>Assuming this exists:<br>void* fcontext_swap (=
void* p, ctxt*src, ctx*dest);<br><br>callcc is equivalent to this:<br><br>c=
tx * callcc(ctx* dst, auto f =3D [](auto x) {} return x; })<br>{<br>=C2=A0=
=C2=A0=C2=A0=C2=A0 struct data { ctx src; function&lt;ctx*(ctx*)&gt; f } da=
ta =3D { {}, std::ref(f) };<br>=C2=A0=C2=A0=C2=A0=C2=A0 auto * otherdata =
=3D (data*)fcontext_swap(&amp;data, &amp;data.src, &amp;dst));<br>=C2=A0=C2=
=A0 =C2=A0 return otherdata-&gt;f(&amp;otherdata-&gt;src));<br>}<br>=C2=A0=
=C2=A0=C2=A0=C2=A0 <br>Although it is not a terribly efficient implementati=
on. Note that the state of the context that we are swapping from is saved i=
n a variable local to callcc, no need for a global. If the target context d=
oesn&#39;t care about the src context, the src context can capture and stor=
e its own continuation by providing &#39;f&#39; on swap. Again, no need for=
 a global.<br><br><br></div>

<p></p>

-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_4610_1038812166.1445447757761--
------=_Part_4609_210998052.1445447757761--

.
