220 37283 <9b3171e2-70c4-4cc6-8fb6-5e180b28eb94@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Nicol Bolas <jmckesson@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Questions about P0876: fibers
Date: Sat, 10 Mar 2018 17:55:48 -0800 (PST)
Lines: 194
Approved: news@gmane.org
Message-ID: <9b3171e2-70c4-4cc6-8fb6-5e180b28eb94@isocpp.org>
References: <ea3e8a64-6363-4460-9ce0-1202768be57d@isocpp.org>
 <CA+wfc19M2fH16RQuyJJugy=BDjSu6RzwULLURRuk-szRbbBdFg@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_9835_1870445691.1520733348987"
X-Trace: blaine.gmane.org 1520733231 25040 195.159.176.226 (11 Mar 2018 01:53:51 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sun, 11 Mar 2018 01:53:51 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCEKFTV6ZUMBBJMZSLKQKGQEEJMTN5Q@isocpp.org Sun Mar 11 02:53:47 2018
Return-path: <std-proposals+bncBCEKFTV6ZUMBBJMZSLKQKGQEEJMTN5Q@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ua0-f197.google.com ([209.85.217.197])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCEKFTV6ZUMBBJMZSLKQKGQEEJMTN5Q@isocpp.org>)
	id 1euqBE-0006Ml-Ct
	for gclcip-std-proposals@m.gmane.org; Sun, 11 Mar 2018 02:53:44 +0100
Original-Received: by mail-ua0-f197.google.com with SMTP id r1sf4496805uae.6
        for <gclcip-std-proposals@m.gmane.org>; Sat, 10 Mar 2018 17:55:51 -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
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=trZbU81LJQsKmaepdKv+ekerW6c/yvsR4ncYFtwzdto=;
        b=rQbI4bdczgJal9nZtHd5DOnRA+d1Xda5EN1ZRVJoqQ6KW8Waeb1lAJaxwWYYyctQiD
         2Lusdy2pc4MmUKHIl6AnmGPmxscHJ2ZKwr8yZ7KzZpiwL+3x3B6fq4idwS0UJJ+i9ZA3
         jL8yek5U4gTrNAgDGgRpT0EFcPP2Bg+EadrEGUbH59oRVsfqc+YvjxEShdzdQD3l9+v0
         gn8XH/yCuLWhfNRHUoGOAQ4DhF82hlLO9PvUTL4NamWN0Zt9Y9GJzP7JbNHvkfZWSKqu
         4l0G+Lt//U+5a/gENxZwl9yWcQAfbme8Es3wJxbaj01EfuQMAAFdvR5maVXQGRu3JU0a
         XxGw==
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=trZbU81LJQsKmaepdKv+ekerW6c/yvsR4ncYFtwzdto=;
        b=OCQ+WsHWbUGyOgWPl9IpHEir4/OBZdAxTaMX9fWVPX2FybV/BrVIKpSKDzXbPZwS1y
         TKfhw+6cYQJFpsYLuVwEM8zm3NzK/bp4WieD3huVRDezS3r2Q+45g/PY9BWzUn+vYUhd
         2aBrvvMwuq/ygga3VrTpcZV00/0ataRZxaKl0i8IGfiuUrUbVeWG9BEe0wor/h2suybL
         AOr7dpPpqFdmDNIFo7Ti4Oppcf8E6Ne6UV50awAVeHxudk2FbTmFwj6JzjIFaTzMdqe1
         SPW9QD/PHEXcMhf7LmnciodwywsgBCD7TlFI3dtlkyTTzLKetcrbZuW0g9Dhcp89VZzc
         JL7w==
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=trZbU81LJQsKmaepdKv+ekerW6c/yvsR4ncYFtwzdto=;
        b=bdICK9ODiR1Avohj4jb9o0c0CqByAN+BIVsLEjUfH2agkFki/OhDGoTP8n9+AG9XWP
         OJZqzv9af6IgmysrEczSIG7y0pElOapJBDm9b3spc2R7hWOpnKEuV11gvnZVzHBcUYVl
         +6uCA77RloYGBmVcoAZaM19xmwEANoEE2ER76FjFmjU/4dAUcnaVdlcq59YOFLa9gsOa
         9M9heyupJGjR29Pm4x0YM4orP/Oh9bziDaz0gqrP4hp7u1Lu2Cmzpd6iLuQ9imZNMXbm
         8/nDTvQGys3FfL4mFP/XjwVqEh31iq0slRMZlub1LfNQbaEOnJEW9M59TyoeR2PyTLNW
         QX9Q==
X-Gm-Message-State: AElRT7G6trnyimMyRHuyaled2C1fCFh0l3waXRWzWRneZWwvGGq7eeoM
	bkJpVSawcDAXYSYWdsepbVYEHg==
X-Google-Smtp-Source: AG47ELv0q+O/nhiU8/ae0KGv2eRU1FrTUGmRIHc5TCEETn7h5jliel1MfZ2eyWwEQBSsVAwPdN8rPQ==
X-Received: by 10.176.86.76 with SMTP id z12mr1730592uaa.36.1520733350922;
        Sat, 10 Mar 2018 17:55:50 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.31.158.3 with SMTP id h3ls5623348vke.11.gmail; Sat, 10 Mar
 2018 17:55:49 -0800 (PST)
X-Received: by 10.31.16.33 with SMTP id g33mr415430vki.13.1520733349509;
        Sat, 10 Mar 2018 17:55:49 -0800 (PST)
In-Reply-To: <CA+wfc19M2fH16RQuyJJugy=BDjSu6RzwULLURRuk-szRbbBdFg@mail.gmail.com>
X-Original-Sender: jmckesson@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:37283
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/37283>

------=_Part_9835_1870445691.1520733348987
Content-Type: multipart/alternative; 
	boundary="----=_Part_9836_113226171.1520733348988"

------=_Part_9836_113226171.1520733348988
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Saturday, March 10, 2018 at 4:37:54 PM UTC-5, Oliver Kowalke wrote:
>
> 2018-03-10 21:55 GMT+01:00 Nicol Bolas <jmck...@gmail.com <javascript:>>:
>
>> * It's not clear to me exactly how `resume_with` works, with regard to=
=20
>> the underlying parts of the stack. That is, is there a way to use=20
>> `resume_with` to execute the given function, then immediately go back an=
d=20
>> resume the execution of whatever was below it on the fiber's stack?=20
>>
>
> yes, the proposal contains an example describing how resume_with() works
>
>
One question about this. I see that the return value from an injected=20
function is passed back to the previously executing call to=20
`resume/resume_with` on the underlying call stack. But... what happens if=
=20
there *is no* underlying call stack yet. That is, you have a fresh=20
`std::fiber` which has never been `resume`d, and you call `resume_with` on=
=20
it.

My guess is that the return value will be passed as the *parameter* to the=
=20
fiber's entry function. But I don't think your current proposal says that.=
=20
Or at least, the definition of `resume_with` doesn't seem to acknowledge=20
that possibility.

Oh, and one other thing. The proposal says this:

When calling `resume()`, it is conventional to replace the=20
> newly-invalidated instance =E2=80=93 the instance on which `resume()` was=
 called =E2=80=93=20
> with the new instance returned by that `resume()` call. This helps to avo=
id=20
> inadvertent calls to `resume()` on the old, invalidated instance.
>

That sounds like a good convention. So maybe there should be a couple of=20
global helper functions to help people adhere to it:

void resume(std::fiber &&f) {f =3D std::move(f).resume();}

template<typename Fn>
void resume_with(std::fiber &&f, Fn &&fn) {f =3D std::move(f).resume_with(s=
td
::forward<Fn>(fn));}

These could be member functions (with the names `resume_inplace` and=20
`resume_with_inplace`) instead of free functions.

--=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/9b3171e2-70c4-4cc6-8fb6-5e180b28eb94%40isocpp.or=
g.

------=_Part_9836_113226171.1520733348988
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Saturday, March 10, 2018 at 4:37:54 PM UTC-5, Oliver Ko=
walke wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-lef=
t: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><=
div><div class=3D"gmail_quote">2018-03-10 21:55 GMT+01:00 Nicol Bolas <span=
 dir=3D"ltr">&lt;<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-m=
ailto=3D"bIUO0GNRAAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;jav=
ascript:&#39;;return true;" onclick=3D"this.href=3D&#39;javascript:&#39;;re=
turn true;">jmck...@gmail.com</a>&gt;</span>:<br><div></div><blockquote cla=
ss=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">* It&#39;s not clear to=
 me exactly how `resume_with` works, with regard to the underlying parts of=
 the stack. That is, is there a way to use `resume_with` to execute the giv=
en function, then immediately go back and resume the execution of whatever =
was below it on the fiber&#39;s stack? </div></blockquote><div><br></div><d=
iv>yes, the proposal contains an example describing how resume_with() works=
<br></div></div><br></div></div></blockquote><div><br>One question about th=
is. I see that the return value from an injected function is passed back to=
 the previously executing call to `resume/resume_with` on the underlying ca=
ll stack. But... what happens if there <i>is no</i> underlying call stack y=
et. That is, you have a fresh `std::fiber` which has never been `resume`d, =
and you call `resume_with` on it.<br><br>My guess is that the return value =
will be passed as the <i>parameter</i> to the fiber&#39;s entry function. B=
ut I don&#39;t think your current proposal says that. Or at least, the defi=
nition of `resume_with` doesn&#39;t seem to acknowledge that possibility.<b=
r><br>Oh, and one other thing. The proposal says this:<br><br><blockquote c=
lass=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; border-left: 1px s=
olid rgb(204, 204, 204); padding-left: 1ex;">When calling `resume()`, it is=
 conventional to replace the newly-invalidated instance =E2=80=93 the insta=
nce on which `resume()` was called =E2=80=93 with the new instance returned=
 by that `resume()` call. This helps to avoid inadvertent calls to `resume(=
)` on the old, invalidated instance.<br></blockquote><br>That sounds like a=
 good convention. So maybe there should be a couple of global helper functi=
ons to help people adhere to it:<br><br><div style=3D"background-color: rgb=
(250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; bor=
der-width: 1px; overflow-wrap: break-word;" class=3D"prettyprint"><code cla=
ss=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #008=
;" class=3D"styled-by-prettify">void</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> resume</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">std</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
fiber </span><span style=3D"color: #660;" class=3D"styled-by-prettify">&amp=
;&amp;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">f</s=
pan><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 style=3D"color: #=
000;" class=3D"styled-by-prettify">f </span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> std</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify">move</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">f</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">).</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify">resume</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">();}</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br><br></span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">template</span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">typename</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"=
styled-by-prettify">Fn</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
void</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> resum=
e_with</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify">std</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">fiber </span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">&amp;&amp;</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify">f</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"styl=
ed-by-prettify">Fn</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">&=
amp;&amp;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">f=
n</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">f </span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> std</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify">move</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">f</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">).</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify">resume_with</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">std</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify">forward</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">Fn</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">&gt;(</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify">fn</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">));}</span></div></code></div><br>These could be member functions (with =
the names `resume_inplace` and `resume_with_inplace`) instead of free funct=
ions.<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/9b3171e2-70c4-4cc6-8fb6-5e180b28eb94%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/9b3171e2-70c4-4cc6-8fb6-5e180b28eb94=
%40isocpp.org</a>.<br />

------=_Part_9836_113226171.1520733348988--

------=_Part_9835_1870445691.1520733348987--

.
