220 21927 <CA+wfc1_mDmHcfE8-peKxfL+_kFF1UrOt4daw=mEAuT_-Rvn9Ng@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: Oliver Kowalke <oliver.kowalke@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 19:35:48 +0200
Lines: 187
Approved: news@gmane.org
Message-ID: <CA+wfc1_mDmHcfE8-peKxfL+_kFF1UrOt4daw=mEAuT_-Rvn9Ng@mail.gmail.com>
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>
 <e9b4c568-2a00-4f25-8324-921ca1926abe@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=047d7b33c6a642e3b00522a0d078
X-Trace: ger.gmane.org 1445449003 8938 80.91.229.3 (21 Oct 2015 17:36:43 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 21 Oct 2015 17:36:43 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCLZHP5J7MHRBCE2T6YQKGQELMXT2KI@isocpp.org Wed Oct 21 19:36:25 2015
Return-path: <std-proposals+bncBCLZHP5J7MHRBCE2T6YQKGQELMXT2KI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qk0-f200.google.com ([209.85.220.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCLZHP5J7MHRBCE2T6YQKGQELMXT2KI@isocpp.org>)
	id 1ZoxJ3-000615-SN
	for gclcip-std-proposals@m.gmane.org; Wed, 21 Oct 2015 19:36:10 +0200
Original-Received: by qkck6 with SMTP id k6sf84920130qkc.1
        for <gclcip-std-proposals@m.gmane.org>; Wed, 21 Oct 2015 10:36:09 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:in-reply-to:references:from:date
         :message-id:subject:to:content-type:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=2FjCo7Aq7KAYdnPV+mqS8DGWREFyKRot0FQXMicSM/A=;
        b=YLs5KeqcsSDKZPfyG0Ga9vmLCCeKz0JWOilMN7uquGLlA2qj+JG1cXSIgDG6FrgBDJ
         g3i9TZLLrWv/GLybW0kGNh7otawXf68ZmutqUcaBM+Jm/3Hk9dbamqOVy3xgW2NLzSgP
         N4WVzeMSlaHwG7FONl9eklblUH9QPz+hniFwhrjOD09YSSKrvJwLiLz1let/HFj61sPs
         5tFaNatvuDlLGtH+0TjDhpYrPLrFFyIUUDK+HxCvTImrzySuwzOTrO6zn4hn+Ciw2g4z
         cSAwpT3mn0e3V7Aq2DU+wbIeqqRKEPmBKLHCUlseYUBjrGOzJWJC2oJaTwhB9eJtHxN0
         CCGA==
X-Gm-Message-State: ALoCoQmnw9caB7U5Lhb3x7lsStAPw8Y3CLhlYLSUg/huDoKsA42Sba/EWDouZchymgt5j0jfi+F8
X-Received: by 10.13.236.135 with SMTP id v129mr9550171ywe.9.1445448968970;
        Wed, 21 Oct 2015 10:36:08 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.182.196.102 with SMTP id il6ls462629obc.17.gmail; Wed, 21 Oct
 2015 10:36:08 -0700 (PDT)
X-Received: by 10.60.67.1 with SMTP id j1mr7525758oet.61.1445448968067;
        Wed, 21 Oct 2015 10:36:08 -0700 (PDT)
Original-Received: from mail-ob0-x22f.google.com (mail-ob0-x22f.google.com. [2607:f8b0:4003:c01::22f])
        by mx.google.com with ESMTPS id cw3si6113565oec.8.2015.10.21.10.36.08
        for <std-proposals@isocpp.org>
        (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Wed, 21 Oct 2015 10:36:08 -0700 (PDT)
Received-SPF: pass (google.com: domain of oliver.kowalke@gmail.com designates 2607:f8b0:4003:c01::22f as permitted sender) client-ip=2607:f8b0:4003:c01::22f;
Original-Received: by obbda8 with SMTP id da8so46840771obb.1
        for <std-proposals@isocpp.org>; Wed, 21 Oct 2015 10:36:08 -0700 (PDT)
X-Received: by 10.60.125.131 with SMTP id mq3mr6978657oeb.8.1445448967707;
 Wed, 21 Oct 2015 10:36:07 -0700 (PDT)
Original-Received: by 10.76.71.233 with HTTP; Wed, 21 Oct 2015 10:35:48 -0700 (PDT)
In-Reply-To: <e9b4c568-2a00-4f25-8324-921ca1926abe@isocpp.org>
X-Original-Sender: oliver.kowalke@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of oliver.kowalke@gmail.com designates 2607:f8b0:4003:c01::22f as
 permitted sender) smtp.mailfrom=oliver.kowalke@gmail.com;       dkim=pass
 header.i=@gmail.com;       dmarc=pass (p=NONE dis=NONE) header.from=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:21927
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/21927>

--047d7b33c6a642e3b00522a0d078
Content-Type: text/plain; charset=UTF-8

2015-10-21 19:15 GMT+02:00 Giovanni Piero Deretta <gpderetta@gmail.com>:

> 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>:
>>
>>>
>>> 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
>

boost.context contains examples demonstrating why I introduced
execution_context::current()

main() -- jump to --> ctx1 -- jump to --> main()

void foo( execution_context * mctx) {
  ( * mctx)();
}

int main () {
  execution_context mctx = execution_context::current();
  execution_context ctx1 = execution_context( foo);
  ctx1( & mctx);
  execution_context ctx2 = execution_context( bar);
  ctx2( & mctx);
  return 0;
}

the body of main might occur at any function/at arbitrary call chain


>
>>
>> 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.
>

do you have an suggestion how the API should changed

-- 

--- 
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/.

--047d7b33c6a642e3b00522a0d078
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">2015=
-10-21 19:15 GMT+02:00 Giovanni Piero Deretta <span dir=3D"ltr">&lt;<a href=
=3D"mailto:gpderetta@gmail.com" target=3D"_blank">gpderetta@gmail.com</a>&g=
t;</span>:<br><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px=
 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Wednesda=
y, October 21, 2015 at 5:45:22 PM UTC+1, Oliver Kowalke wrote:<span class=
=3D""><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;b=
order-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr"><d=
iv><div class=3D"gmail_quote">2015-10-21 15:43 GMT+02:00 Giovanni Piero Der=
etta <span dir=3D"ltr">&lt;<a rel=3D"nofollow">gpde...@gmail.com</a>&gt;</s=
pan>:<br><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"><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 experience.<br></div></=
blockquote><div><br></div><div>for a context switch you need the current co=
ntext, which is required to be preserved, and a target context, which has t=
o be resumed<br></div><div>I thought it is convenient only to know the targ=
et context and simply call execution-context::operator() to switch to the t=
arget-context.<br></div></div></div></div></blockquote></span><div><br>it i=
s very convenient, but it doesn&#39;t need to save the current context <br>=
</div></blockquote><div><br></div><div>boost.context contains examples demo=
nstrating why I introduced execution_context::current()<br><br></div><div>m=
ain() -- jump to --&gt; ctx1 -- jump to --&gt; main()<br></div><div>=C2=A0<=
br></div><div>void foo( execution_context * mctx) {<br></div><div>=C2=A0 ( =
* mctx)();<br></div><div>}<br></div><div><br></div><div>int main () {<br></=
div><div>=C2=A0 execution_context mctx =3D execution_context::current();<br=
>=C2=A0 execution_context ctx1 =3D execution_context( foo);<br></div><div>=
=C2=A0 ctx1( &amp; mctx);<br>=C2=A0 execution_context ctx2 =3D execution_co=
ntext( bar);<br>=C2=A0 ctx2( &amp; mctx);</div><div>=C2=A0 return 0;<br>}<b=
r><br></div><div>the body of main might occur at any function/at arbitrary =
call chain <br></div><div><br></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>=C2=A0</div><span class=3D""><blockquote class=3D"gmail_quo=
te" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204=
);padding-left:1ex"><div dir=3D"ltr"><div><div class=3D"gmail_quote"><div><=
br></div><div>it is a small API - one function to resume the context, one f=
unction to access the current context<br></div><div>=C2=A0</div><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>=C2=A0callcc is the task switch=
ing primitive: it suspend the current thread of execution and resumes the t=
arget one. On the just awakened thread of execution it returns the just sus=
pened continuation.<br></div></blockquote><div>=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 (execution_context::operator()) to the =
target context.<br></div><div>with your callcc the target context always kn=
ows its calling context (parent context, what would be the right wording?).=
<br></div><div>but in some cases the target context does not need to know f=
rom which context it was resumed.<br></div><div>maybe callcc and execution_=
context are equivalent<br></div></div></blockquote></span><div><br>With par=
ameter passing they are have equivalent expressibility. It is trivial to im=
plement 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>ctx * 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 } data =3D { {}, std::ref(f) };<br=
>=C2=A0=C2=A0=C2=A0=C2=A0 auto * otherdata =3D (data*)fcontext_swap(&amp;da=
ta, &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 i=
t is not a terribly efficient implementation. Note that the state of the co=
ntext that we are swapping from is saved in a variable local to callcc, no =
need for a global. If the target context doesn&#39;t care about the src con=
text, the src context can capture and store its own continuation by providi=
ng &#39;f&#39; on swap. Again, no need for a global.<br></div></blockquote>=
</div><br></div><div class=3D"gmail_extra">do you have an suggestion how th=
e API should changed<br></div></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 />

--047d7b33c6a642e3b00522a0d078--

.
