Topic: Criticism of resumable functions proposal (N3858)
Author: Maciej Gajewski <maciej.gajewski0@gmail.com>
Date: Fri, 24 Jan 2014 02:30:10 -0800 (PST)
Raw View
------=_Part_431_19078414.1390559410170
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Hi everyone
I would love to see resumable functions/coroutines introduced into C++=20
standard. It would make my life, and lives of many other software=20
developers, easier. It would solve many problems, encountered in many kinds=
=20
of projects.
Unfortunately, I find the resumable/await proposal (N3858) flawed. I=E2=80=
=99ll=20
describe the flaws below, and in another message I will present an=20
alternative idea.
Problems with the resumable functions/await:
1. It does not solve real-life problems
As a programmer, I would like to use resumable functions to:
a. Implement generators,
b. Convert my multi-threaded, IO-heavy application into a single-threaded=
=20
one, preserving the logical flow of functions, but using asynchronous IO,
c. Re-write my single-threaded applications using asynchronous IO (for=20
instance boost.asio) to use coroutines, so that the performance gain from=
=20
async io is preserved, while the code is cleaner, easier to read and=20
maintain.
resumable/await would not help me with any of it. Writing generators is=20
awkward (even authors of the proposal admit it chapter 5.2). As for=20
asynchronous IO: there is no concrete example how to integrate=20
resumable/await with any existing async IO solutions; instead, the proposal=
=20
vaguely mentions a =E2=80=9Cscheduling logic inside the runtime=E2=80=9D.
2. It=E2=80=99s high level solution
Resumable functions are high-level mechanisms implemented as language=20
features. All the features provided by the solution could be implemented as=
=20
a library instead, given the appropriate low-level primitives are available=
..
3. =E2=80=98await=E2=80=99 can only be used in resumable function.
The =E2=80=98await=E2=80=99 operation can only be used at the level of resu=
mable function.=20
In other words: the decision to suspend execution has to be taken in the=20
function=E2=80=99s body, it can=E2=80=99t be delegated to another function.
I realise that this is by design, to allow for rewriting of the function=20
body by the compiler, but this makes integration with existing code=20
impossible.
Consider the following code:
void handle_http_request(std::istream& input, std::ostream& output)
{
Poco::Net::HTTPRequest request;
request.read(input);
// ... read request body here
// ... produce and write response here
}
This code could be either synchronous (using blocking IO) or asynchronous=
=20
(using coroutines). The iostreams provide sufficient abstraction.
In the asynchronous case, the decision to suspend execution can only be=20
made several levels below: below Poco=E2=80=99s HTTP, below std::iostream, =
below=20
std::streambuf, at the point when the actual IO operation is performed.
4. std::future is required to suspend execution
future/promise may be nice, high-level idioms for asynchronous operations,=
=20
but making them a requirement makes some use cases awkward or even=20
impossible to implement. Generators are difficult to implement, and=20
existing code would have to be wrapped or re-written.
5. Resumable functions are =E2=80=98special=E2=80=99
They have to be decorated, they have certain restrictions put on them,=20
exceptions use is limited. Normal functions, functors or lambdas can=E2=80=
=99t be=20
used as a resumable functions, just as they can be used as thread routines.
6. Many questions remain unanswered
We, C++ programmers like to know what=E2=80=99s going on under the covers. =
And the=20
resumable functions proposal leaves too many questions unanswered:
a. What is the lifetime of objects created on stack in resumable functions?
b. When are the resources required to create such a function (side stack)=
=20
released?
c. How are these functions resumed?
d. If get() is called on a future returned by resumable function, how will=
=20
it block? What device will be used to block and how can it be controlled=20
from the outside?
--=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
------=_Part_431_19078414.1390559410170
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;ma=
rgin-bottom:0pt;" id=3D"docs-internal-guid--8f0f780-c3c7-deb9-2ea5-2595e571=
3f6f"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgro=
und-color:transparent;font-weight:normal;font-style:normal;font-variant:nor=
mal;text-decoration:none;vertical-align:baseline;">Hi everyone</span></p><b=
r><span style=3D"font-size:15px;font-family:Arial;color:#000000;background-=
color:transparent;font-weight:normal;font-style:normal;font-variant:normal;=
text-decoration:none;vertical-align:baseline;"></span><p dir=3D"ltr" style=
=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font=
-size:15px;font-family:Arial;color:#000000;background-color:transparent;fon=
t-weight:normal;font-style:normal;font-variant:normal;text-decoration:none;=
vertical-align:baseline;">I would love to see resumable functions/coroutine=
s introduced into C++ standard. It would make my life, and lives of many ot=
her software developers, easier. It would solve many problems, encountered =
in many kinds of projects.<br></span></p><br><span style=3D"font-size:15px;=
font-family:Arial;color:#000000;background-color:transparent;font-weight:no=
rmal;font-style:normal;font-variant:normal;text-decoration:none;vertical-al=
ign:baseline;"></span><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0=
pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;colo=
r:#000000;background-color:transparent;font-weight:normal;font-style:normal=
;font-variant:normal;text-decoration:none;vertical-align:baseline;">Unfortu=
nately, I find the resumable/await proposal (N3858) flawed. I=E2=80=99ll de=
scribe the flaws below, and in another message I will present an alternativ=
e idea.</span></p><br><span style=3D"font-size:15px;font-family:Arial;color=
:#000000;background-color:transparent;font-weight:normal;font-style:normal;=
font-variant:normal;text-decoration:none;vertical-align:baseline;"></span><=
p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;">=
<span style=3D"font-size:15px;font-family:Arial;color:#000000;background-co=
lor:transparent;font-weight:normal;font-style:normal;font-variant:normal;te=
xt-decoration:none;vertical-align:baseline;">Problems with the resumable fu=
nctions/await:</span></p><br><span style=3D"font-size:15px;font-family:Aria=
l;color:#000000;background-color:transparent;font-weight:normal;font-style:=
normal;font-variant:normal;text-decoration:none;vertical-align:baseline;"><=
/span><p dir=3D"ltr" style=3D"line-height: 1.15; margin-top: 0pt; margin-bo=
ttom: 0pt;"><font size=3D"4"><span style=3D"font-family: Arial; color: rgb(=
0, 0, 0); background-color: transparent; font-weight: normal; font-style: n=
ormal; font-variant: normal; text-decoration: none; vertical-align: baselin=
e;">1. It does not solve real-life problems</span></font></p><br><span styl=
e=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transp=
arent;font-weight:normal;font-style:normal;font-variant:normal;text-decorat=
ion:none;vertical-align:baseline;"></span><p dir=3D"ltr" style=3D"line-heig=
ht:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;fo=
nt-family:Arial;color:#000000;background-color:transparent;font-weight:norm=
al;font-style:normal;font-variant:normal;text-decoration:none;vertical-alig=
n:baseline;">As a programmer, I would like to use resumable functions to:</=
span></p><br><span style=3D"font-size:15px;font-family:Arial;color:#000000;=
background-color:transparent;font-weight:normal;font-style:normal;font-vari=
ant:normal;text-decoration:none;vertical-align:baseline;"></span><p dir=3D"=
ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;text-indent=
: 36pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000000;back=
ground-color:transparent;font-weight:normal;font-style:normal;font-variant:=
normal;text-decoration:none;vertical-align:baseline;">a. Implement generato=
rs,</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margi=
n-bottom:0pt;text-indent: 36pt;"><span style=3D"font-size:15px;font-family:=
Arial;color:#000000;background-color:transparent;font-weight:normal;font-st=
yle:normal;font-variant:normal;text-decoration:none;vertical-align:baseline=
;">b. Convert my multi-threaded, IO-heavy application into a single-threade=
d one, preserving the logical flow of functions, but using asynchronous IO,=
</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-b=
ottom:0pt;text-indent: 36pt;"><span style=3D"font-size:15px;font-family:Ari=
al;color:#000000;background-color:transparent;font-weight:normal;font-style=
:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;">=
c. Re-write my single-threaded applications using asynchronous IO (for inst=
ance boost.asio) to use coroutines, so that the performance gain from async=
io is preserved, while the code is cleaner, easier to read and maintain.</=
span></p><br><span style=3D"font-size:15px;font-family:Arial;color:#000000;=
background-color:transparent;font-weight:normal;font-style:normal;font-vari=
ant:normal;text-decoration:none;vertical-align:baseline;"></span><p dir=3D"=
ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span sty=
le=3D"font-size:15px;font-family:Arial;color:#000000;background-color:trans=
parent;font-weight:normal;font-style:normal;font-variant:normal;text-decora=
tion:none;vertical-align:baseline;">resumable/await would not help me with =
any of it. Writing generators is awkward (even authors of the proposa=
l admit it chapter 5.2). As for asynchronous IO: there is no concrete examp=
le how to integrate resumable/await with any existing async IO solutions; i=
nstead, the proposal vaguely mentions a =E2=80=9Cscheduling logic inside th=
e runtime=E2=80=9D.</span></p><br><span style=3D"font-size:15px;font-family=
:Arial;color:#000000;background-color:transparent;font-weight:normal;font-s=
tyle:normal;font-variant:normal;text-decoration:none;vertical-align:baselin=
e;"></span><p dir=3D"ltr" style=3D"line-height: 1.15; margin-top: 0pt; marg=
in-bottom: 0pt;"><font size=3D"4"><span style=3D"font-family: Arial; color:=
rgb(0, 0, 0); background-color: transparent; font-weight: normal; font-sty=
le: normal; font-variant: normal; text-decoration: none; vertical-align: ba=
seline;">2. It=E2=80=99s high level solution</span></font></p><br><span sty=
le=3D"font-size:15px;font-family:Arial;color:#000000;background-color:trans=
parent;font-weight:normal;font-style:normal;font-variant:normal;text-decora=
tion:none;vertical-align:baseline;"></span><p dir=3D"ltr" style=3D"line-hei=
ght:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;f=
ont-family:Arial;color:#000000;background-color:transparent;font-weight:nor=
mal;font-style:normal;font-variant:normal;text-decoration:none;vertical-ali=
gn:baseline;">Resumable functions are high-level mechanisms implemented as =
language features. All the features provided by the solution could be imple=
mented as a library instead, given the appropriate low-level primitives are=
available.</span></p><br><span style=3D"font-size:15px;font-family:Arial;c=
olor:#000000;background-color:transparent;font-weight:normal;font-style:nor=
mal;font-variant:normal;text-decoration:none;vertical-align:baseline;"></sp=
an><p dir=3D"ltr" style=3D"line-height: 1.15; margin-top: 0pt; margin-botto=
m: 0pt;"><font size=3D"4"><span style=3D"font-family: Arial; color: rgb(0, =
0, 0); background-color: transparent; font-weight: normal; font-style: norm=
al; font-variant: normal; text-decoration: none; vertical-align: baseline;"=
>3. =E2=80=98await=E2=80=99 can only be used in resumable function.</span><=
/font></p><br><span style=3D"font-size:15px;font-family:Arial;color:#000000=
;background-color:transparent;font-weight:normal;font-style:normal;font-var=
iant:normal;text-decoration:none;vertical-align:baseline;"></span><p dir=3D=
"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span st=
yle=3D"font-size:15px;font-family:Arial;color:#000000;background-color:tran=
sparent;font-weight:normal;font-style:normal;font-variant:normal;text-decor=
ation:none;vertical-align:baseline;">The =E2=80=98await=E2=80=99 operation =
can only be used at the level of resumable function. In other words: the de=
cision to suspend execution has to be taken in the function=E2=80=99s body,=
it can=E2=80=99t be delegated to another function.</span></p><p dir=3D"ltr=
" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=
=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transpa=
rent;font-weight:normal;font-style:normal;font-variant:normal;text-decorati=
on:none;vertical-align:baseline;">I realise that this is by design, to allo=
w for rewriting of the function body by the compiler, but this makes integr=
ation with existing code impossible.</span></p><br><span style=3D"font-size=
:15px;font-family:Arial;color:#000000;background-color:transparent;font-wei=
ght:normal;font-style:normal;font-variant:normal;text-decoration:none;verti=
cal-align:baseline;"></span><p dir=3D"ltr" style=3D"line-height:1.15;margin=
-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Aria=
l;color:#000000;background-color:transparent;font-weight:normal;font-style:=
normal;font-variant:normal;text-decoration:none;vertical-align:baseline;">C=
onsider the following code:</span></p><br><span style=3D"font-size:15px;fon=
t-family:Arial;color:#000000;background-color:transparent;font-weight:norma=
l;font-style:normal;font-variant:normal;text-decoration:none;vertical-align=
:baseline;"></span><div class=3D"prettyprint" style=3D"background-color: rg=
b(250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; bo=
rder-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div c=
lass=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">void</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> handle_http_request</span><span 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"color: #660;" class=3D"styled-by-prettify">::</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify">istream</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">&</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> input</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> std</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">ostream</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> output</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br></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><code class=3D"prettyprint"><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> </span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"></span></code><span style=3D"color: #606;" class=3D"style=
d-by-prettify">Poco</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">::</span><span style=3D"color: #606;" class=3D"styled-by-prettify"=
>Net</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</sp=
an><span style=3D"color: #606;" class=3D"styled-by-prettify">HTTPRequest</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> request</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> reques=
t</span><span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify">read</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">input</span><span style=3D"color:=
#660;" class=3D"styled-by-prettify">);</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"><br></span><span style=3D"color: #800;" class=
=3D"styled-by-prettify"><code class=3D"prettyprint"><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"></span></code>// ... read request bo=
dy here</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
></span><span style=3D"color: #800;" class=3D"styled-by-prettify"><code cla=
ss=3D"prettyprint"><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> </span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"></span></code>// ... produce and write response here</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br></span></div></code></div><br><br><spa=
n style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:=
transparent;font-weight:normal;font-style:normal;font-variant:normal;text-d=
ecoration:none;vertical-align:baseline;"></span><p dir=3D"ltr" style=3D"lin=
e-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:1=
5px;font-family:Arial;color:#000000;background-color:transparent;font-weigh=
t:normal;font-style:normal;font-variant:normal;text-decoration:none;vertica=
l-align:baseline;">This code could be either synchronous (using blocking IO=
) or asynchronous (using coroutines). The iostreams provide sufficient abst=
raction.</span></p><br><span style=3D"font-size:15px;font-family:Arial;colo=
r:#000000;background-color:transparent;font-weight:normal;font-style:normal=
;font-variant:normal;text-decoration:none;vertical-align:baseline;"></span>=
<p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"=
><span style=3D"font-size:15px;font-family:Arial;color:#000000;background-c=
olor:transparent;font-weight:normal;font-style:normal;font-variant:normal;t=
ext-decoration:none;vertical-align:baseline;">In the asynchronous case, the=
decision to suspend execution can only be made several levels below: below=
Poco=E2=80=99s HTTP, below std::iostream, below std::streambuf, at the poi=
nt when the actual IO operation is performed.</span></p><br><span style=3D"=
font-size:15px;font-family:Arial;color:#000000;background-color:transparent=
;font-weight:normal;font-style:normal;font-variant:normal;text-decoration:n=
one;vertical-align:baseline;"></span><p dir=3D"ltr" style=3D"line-height: 1=
..15; margin-top: 0pt; margin-bottom: 0pt;"><font size=3D"4"><span style=3D"=
font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; fon=
t-weight: normal; font-style: normal; font-variant: normal; text-decoration=
: none; vertical-align: baseline;">4. std::future is required to suspend ex=
ecution</span></font></p><br><span style=3D"font-size:15px;font-family:Aria=
l;color:#000000;background-color:transparent;font-weight:normal;font-style:=
normal;font-variant:normal;text-decoration:none;vertical-align:baseline;"><=
/span><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom=
:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgr=
ound-color:transparent;font-weight:normal;font-style:normal;font-variant:no=
rmal;text-decoration:none;vertical-align:baseline;">future/promise may be n=
ice, high-level idioms for asynchronous operations, but making them a requi=
rement makes some use cases awkward or even impossible to implement. Genera=
tors are difficult to implement, and existing code would have to be wrapped=
or re-written.</span></p><br><span style=3D"font-size:15px;font-family:Ari=
al;color:#000000;background-color:transparent;font-weight:normal;font-style=
:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;">=
</span><p dir=3D"ltr" style=3D"line-height: 1.15; margin-top: 0pt; margin-b=
ottom: 0pt;"><font size=3D"4"><span style=3D"font-family: Arial; color: rgb=
(0, 0, 0); background-color: transparent; font-weight: normal; font-style: =
normal; font-variant: normal; text-decoration: none; vertical-align: baseli=
ne;">5. Resumable functions are =E2=80=98special=E2=80=99</span></font></p>=
<br><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgroun=
d-color:transparent;font-weight:normal;font-style:normal;font-variant:norma=
l;text-decoration:none;vertical-align:baseline;"></span><p dir=3D"ltr" styl=
e=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"fon=
t-size:15px;font-family:Arial;color:#000000;background-color:transparent;fo=
nt-weight:normal;font-style:normal;font-variant:normal;text-decoration:none=
;vertical-align:baseline;">They have to be decorated, they have certain res=
trictions put on them, exceptions use is limited. Normal functions, functor=
s or lambdas can=E2=80=99t be used as a resumable functions, just as they c=
an be used as thread routines.</span></p><br><span style=3D"font-size:15px;=
font-family:Arial;color:#000000;background-color:transparent;font-weight:no=
rmal;font-style:normal;font-variant:normal;text-decoration:none;vertical-al=
ign:baseline;"></span><p dir=3D"ltr" style=3D"line-height: 1.15; margin-top=
: 0pt; margin-bottom: 0pt;"><font size=3D"4"><span style=3D"font-family: Ar=
ial; color: rgb(0, 0, 0); background-color: transparent; font-weight: norma=
l; font-style: normal; font-variant: normal; text-decoration: none; vertica=
l-align: baseline;">6. Many questions remain unanswered</span></font></p><b=
r><span style=3D"font-size:15px;font-family:Arial;color:#000000;background-=
color:transparent;font-weight:normal;font-style:normal;font-variant:normal;=
text-decoration:none;vertical-align:baseline;"></span><p dir=3D"ltr" style=
=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font=
-size:15px;font-family:Arial;color:#000000;background-color:transparent;fon=
t-weight:normal;font-style:normal;font-variant:normal;text-decoration:none;=
vertical-align:baseline;">We, C++ programmers like to know what=E2=80=99s g=
oing on under the covers. And the resumable functions proposal leaves too m=
any questions unanswered:</span></p><br><span style=3D"font-size:15px;font-=
family:Arial;color:#000000;background-color:transparent;font-weight:normal;=
font-style:normal;font-variant:normal;text-decoration:none;vertical-align:b=
aseline;"></span><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;ma=
rgin-bottom:0pt;text-indent: 36pt;"><span style=3D"font-size:15px;font-fami=
ly:Arial;color:#000000;background-color:transparent;font-weight:normal;font=
-style:normal;font-variant:normal;text-decoration:none;vertical-align:basel=
ine;">a. What is the lifetime of objects created on stack in resumable func=
tions?</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;ma=
rgin-bottom:0pt;text-indent: 36pt;"><span style=3D"font-size:15px;font-fami=
ly:Arial;color:#000000;background-color:transparent;font-weight:normal;font=
-style:normal;font-variant:normal;text-decoration:none;vertical-align:basel=
ine;">b. When are the resources required to create such a function (side st=
ack) released?</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-to=
p:0pt;margin-bottom:0pt;text-indent: 36pt;"><span style=3D"font-size:15px;f=
ont-family:Arial;color:#000000;background-color:transparent;font-weight:nor=
mal;font-style:normal;font-variant:normal;text-decoration:none;vertical-ali=
gn:baseline;">c. How are these functions resumed?</span></p><p dir=3D"ltr" =
style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;text-indent: 36p=
t;"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgroun=
d-color:transparent;font-weight:normal;font-style:normal;font-variant:norma=
l;text-decoration:none;vertical-align:baseline;">d. If get() is called on a=
future returned by resumable function, how will it block? What device will=
be used to block and how can it be controlled from the outside?</span></p>=
<br><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgroun=
d-color:transparent;font-weight:normal;font-style:normal;font-variant:norma=
l;text-decoration:none;vertical-align:baseline;"></span><br><span style=3D"=
font-size:15px;font-family:Arial;color:#000000;background-color:transparent=
;font-weight:normal;font-style:normal;font-variant:normal;text-decoration:n=
one;vertical-align:baseline;"></span><br><span style=3D"font-size:15px;font=
-family:Arial;color:#000000;background-color:transparent;font-weight:normal=
;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:=
baseline;"></span><br><span style=3D"font-size:15px;font-family:Arial;color=
:#000000;background-color:transparent;font-weight:normal;font-style:normal;=
font-variant:normal;text-decoration:none;vertical-align:baseline;"></span><=
br><span style=3D"font-size:15px;font-family:Arial;color:#000000;background=
-color:transparent;font-weight:normal;font-style:normal;font-variant:normal=
;text-decoration:none;vertical-align:baseline;"></span></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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_431_19078414.1390559410170--
.
Author: Evgeny Panasyuk <evgeny.panasyuk@gmail.com>
Date: Tue, 28 Jan 2014 13:50:14 -0800 (PST)
Raw View
------=_Part_4770_5899507.1390945814954
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
24 January 2014, 14:30:10 UTC+4 Maciej Gajewski :
>
>
> Unfortunately, I find the resumable/await proposal (N3858) flawed. I=E2=
=80=99ll=20
> describe the flaws below, and in another message I will present an=20
> alternative idea.
>
>
I share most of your concerns.
It seems that limitations ["3. =E2=80=98await=E2=80=99 can only be used in =
resumable=20
function."] and ["5. Resumable functions are =E2=80=98special=E2=80=99"] ca=
me from leaving=20
possibility for implementor to build them based on stackless coroutines.=20
I.e. "Implementation#2: Heap - allocated activation frames".
Stackless Coroutine basically transforms function with yield/await into=20
object finite-state machine, where function's local variables are move into=
=20
object fields.
In general, stackless coroutines (not N3858) have some advantages over=20
stackfull. For possible implementation refer=20
http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/overview/core/coro=
utine.html=20
..
For instance:
1) Size of required storage for object is known in advance.
2) Fast generators. As function transformed into object with no heap=20
allocations, with no context switches on yield, with good opportunity for=
=20
inlining - I presume that small generators will be faster than alternative=
=20
based on stackful coroutines.
3) As generated finite-state machine is just ordinary C++ object, it can be=
=20
copied or moved. For instance it is possible to copy generator in order to=
=20
save state or "fork" (like in stackless coroutines of Boost.Asio). This is=
=20
also required for implementation of something like List Monad.
But, first of all - there is no ready implementation of such approach. As=
=20
far as I understand, VS2013 __resumable/__await are implemented based on=20
stackful coroutines (this is what I understood from=20
http://channel9.msdn.com/Events/GoingNative/2013/Bringing-await-to-Cpp ).
Second, N3858 does not expose API required to take advantages of=20
stackless-ness - for instance you can't copy or move state (correct me if I=
=20
wrong).
So, if there is no way to take advantages of stackless-ness and there is no=
=20
proof-of-concept implementation - why bring its disadvantages?
Stackful coroutines can be implemented in library form, just like=20
std::thread. There is no need to introduce new special kind of functions.=
=20
There is no need to limit await to "one level".
There is ready library implementation of stackful coroutines -=20
Boost.Coroutine=20
http://www.boost.org/doc/libs/1_55_0/libs/coroutine/doc/html/index.html. It=
=20
works without changes to language, it can yield from arbitrary levels, it=
=20
allows to implement both generators and await.
There is proof-of-concept implementation of exact await syntax based on=20
Boost.Coroutine: https://github.com/panaseleus/await_emu
int bar(int i)
{
// await is not limited by "one level" as in C#
auto result =3D await async([i]{ return reschedule(), i*100; });
return result + i*10;
}
int foo(int i)
{
cout << i << ":\tbegin" << endl;
cout << await async([i]{ return reschedule(), i*10; }) << ":\tbody" << =
endl;
cout << bar(i) << ":\tend" << endl;
return i*1000;
}
void async_user_handler()
{
vector<future<int>> fs;
// instead of `async` at function signature, `asynchronous` should be
// used at the call place:
for(auto i=3D0; i!=3D5; ++i)
fs.push_back( asynchronous([i]{ return foo(i+1); }) );
for(auto &&f : fs)
cout << await f << ":\tafter end" << endl;
}
P.S. Stackful and stackless coroutines have some overlap in use cases, both=
=20
have unique advantages and disadvantages. N3858 tries to allow both to be=
=20
used as underlying implementation, killing all unique advantages and=20
bringing all unique disadvantages of stackless and stackfull coroutines.
--=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
------=_Part_4770_5899507.1390945814954
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">24 January 2014, 14:30:10 UTC+4 Maciej Gajewski :<blockquo=
te 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><span style=3D"fon=
t-size:15px;font-family:Arial;color:#000000;background-color:transparent;fo=
nt-weight:normal;font-style:normal;font-variant:normal;text-decoration:none=
;vertical-align:baseline"></span><p dir=3D"ltr" style=3D"line-height:1.15;m=
argin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:=
Arial;color:#000000;background-color:transparent;font-weight:normal;font-st=
yle:normal;font-variant:normal;text-decoration:none;vertical-align:baseline=
">Unfortunately, I find the resumable/await proposal (N3858) flawed. I=E2=
=80=99ll describe the flaws below, and in another message I will present an=
alternative idea.</span></p><br></div></blockquote><div><br>I share most o=
f your concerns.<br><br>It seems that limitations ["3. =E2=80=98await=E2=80=
=99 can only be used in resumable function."] and ["5. Resumable functions =
are =E2=80=98special=E2=80=99"] came from leaving possibility for implement=
or to build them based on stackless coroutines. I.e. "Implementation#2: Hea=
p - allocated activation frames".<br><br>Stackless Coroutine basically tran=
sforms function with yield/await into object finite-state machine, where fu=
nction's local variables are move into object fields.<br>In general, stackl=
ess coroutines (not N3858) have some advantages over stackfull. For possibl=
e implementation refer http://www.boost.org/doc/libs/1_55_0/doc/html/boost_=
asio/overview/core/coroutine.html .<br>For instance:<br>1) Size of required=
storage for object is known in advance.<br>2) Fast generators. As function=
transformed into object with no heap allocations, with no context switches=
on yield, with good opportunity for inlining - I presume that small genera=
tors will be faster than alternative based on stackful coroutines.<br>3) As=
generated finite-state machine is just ordinary C++ object, it can be copi=
ed or moved. For instance it is possible to copy generator in order to save=
state or "fork" (like in stackless coroutines of Boost.Asio). This is also=
required for implementation of something like List Monad.<br><br>But, firs=
t of all - there is no ready implementation of such approach. As far as I u=
nderstand, VS2013 __resumable/__await are implemented based on stackful cor=
outines (this is what I understood from http://channel9.msdn.com/Events/Goi=
ngNative/2013/Bringing-await-to-Cpp ).<br>Second, N3858 does not expose API=
required to take advantages of stackless-ness - for instance you can't cop=
y or move state (correct me if I wrong).<br>So, if there is no way to take =
advantages of stackless-ness and there is no proof-of-concept implementatio=
n - why bring its disadvantages?<br><br>Stackful coroutines can be implemen=
ted in library form, just like std::thread. There is no need to introduce n=
ew special kind of functions. There is no need to limit await to "one level=
".<br>There is ready library implementation of stackful coroutines - Boost.=
Coroutine http://www.boost.org/doc/libs/1_55_0/libs/coroutine/doc/html/inde=
x.html. It works without changes to language, it can yield from arbitrary l=
evels, it allows to implement both generators and await.<br>There is proof-=
of-concept implementation of exact await syntax based on Boost.Coroutine: h=
ttps://github.com/panaseleus/await_emu<br><div class=3D"prettyprint" style=
=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187);=
border-style: solid; border-width: 1px; word-wrap: break-word;"><code clas=
s=3D"prettyprint"><div class=3D"subprettyprint"><pre><span class=3D"kt"><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">int</span></span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span class=
=3D"nf"><span style=3D"color: #000;" class=3D"styled-by-prettify">bar</span=
></span><span class=3D"p"><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">(</span></span><span class=3D"kt"><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">int</span></span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span class=3D"n"><span style=3D"color: #=
000;" class=3D"styled-by-prettify">i</span></span><span class=3D"p"><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">)</span></span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span class=3D"=
p"><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span></span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>  =
; </span><span class=3D"c1"><span style=3D"color: #800;" class=3D"styled-by=
-prettify">// await is not limited by "one level" as in C#</span></span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br> </=
span><span class=3D"k"><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">auto</span></span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span class=3D"n"><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">result</span></span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span class=3D"o"><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">=3D</span></span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span class=3D"n"><span style=3D"color:=
#000;" class=3D"styled-by-prettify">await</span></span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span class=3D"n"><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">async</span></span><span cl=
ass=3D"p"><span style=3D"color: #660;" class=3D"styled-by-prettify">([</spa=
n></span><span class=3D"n"><span style=3D"color: #000;" class=3D"styled-by-=
prettify">i</span></span><span class=3D"p"><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">]{</span></span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span class=3D"k"><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">return</span></span><span style=3D"color:=
#000;" class=3D"styled-by-prettify"> </span><span class=3D"n"><span style=
=3D"color: #000;" class=3D"styled-by-prettify">reschedule</span></span><spa=
n class=3D"p"><span style=3D"color: #660;" class=3D"styled-by-prettify">(),=
</span></span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span class=3D"n"><span style=3D"color: #000;" class=3D"styled-by-pret=
tify">i</span></span><span class=3D"o"><span style=3D"color: #660;" class=
=3D"styled-by-prettify">*</span></span><span class=3D"mi"><span style=3D"co=
lor: #066;" class=3D"styled-by-prettify">100</span></span><span class=3D"p"=
><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span></span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span clas=
s=3D"p"><span style=3D"color: #660;" class=3D"styled-by-prettify">});</span=
></span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br> =
; </span><span class=3D"k"><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">return</span></span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span class=3D"n"><span style=3D"color: #000;" =
class=3D"styled-by-prettify">result</span></span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span class=3D"o"><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">+</span></span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span class=3D"n"><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">i</span></span><span class=
=3D"o"><span style=3D"color: #660;" class=3D"styled-by-prettify">*</span></=
span><span class=3D"mi"><span style=3D"color: #066;" class=3D"styled-by-pre=
ttify">10</span></span><span class=3D"p"><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span></span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span><span class=3D"p"><span style=3D"color: =
#660;" class=3D"styled-by-prettify">}</span></span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br><br></span><span class=3D"kt"><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">int</span></span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span class=3D"n=
f"><span style=3D"color: #000;" class=3D"styled-by-prettify">foo</span></sp=
an><span class=3D"p"><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">(</span></span><span class=3D"kt"><span style=3D"color: #008;" class=3D=
"styled-by-prettify">int</span></span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> </span><span class=3D"n"><span style=3D"color: #000;"=
class=3D"styled-by-prettify">i</span></span><span class=3D"p"><span style=
=3D"color: #660;" class=3D"styled-by-prettify">)</span></span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span class=3D"p"=
><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span></span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br> =
</span><span class=3D"n"><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify">cout</span></span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span class=3D"o"><span style=3D"color: #660;" class=3D"st=
yled-by-prettify"><<</span></span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span class=3D"n"><span style=3D"color: #00=
0;" class=3D"styled-by-prettify">i</span></span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span class=3D"o"><span style=3D"col=
or: #660;" class=3D"styled-by-prettify"><<</span></span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span class=3D"s"><s=
pan style=3D"color: #080;" class=3D"styled-by-prettify">":</span></span><sp=
an class=3D"se"><span style=3D"color: #080;" class=3D"styled-by-prettify">\=
t</span></span><span class=3D"s"><span style=3D"color: #080;" class=3D"styl=
ed-by-prettify">begin"</span></span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span class=3D"o"><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify"><<</span></span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span class=3D"n"><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">endl</span></span><span class=3D"=
p"><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span></span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>  =
; </span><span class=3D"n"><span style=3D"color: #000;" class=3D"styled-by-=
prettify">cout</span></span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span class=3D"o"><span style=3D"color: #660;" class=3D"=
styled-by-prettify"><<</span></span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span class=3D"n"><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">await</span></span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span class=3D"n"><span style=
=3D"color: #000;" class=3D"styled-by-prettify">async</span></span><span cla=
ss=3D"p"><span style=3D"color: #660;" class=3D"styled-by-prettify">([</span=
></span><span class=3D"n"><span style=3D"color: #000;" class=3D"styled-by-p=
rettify">i</span></span><span class=3D"p"><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">]{</span></span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span class=3D"k"><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">return</span></span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span class=3D"n"><span style=
=3D"color: #000;" class=3D"styled-by-prettify">reschedule</span></span><spa=
n class=3D"p"><span style=3D"color: #660;" class=3D"styled-by-prettify">(),=
</span></span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span class=3D"n"><span style=3D"color: #000;" class=3D"styled-by-pret=
tify">i</span></span><span class=3D"o"><span style=3D"color: #660;" class=
=3D"styled-by-prettify">*</span></span><span class=3D"mi"><span style=3D"co=
lor: #066;" class=3D"styled-by-prettify">10</span></span><span class=3D"p">=
<span style=3D"color: #660;" class=3D"styled-by-prettify">;</span></span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span class=
=3D"p"><span style=3D"color: #660;" class=3D"styled-by-prettify">})</span><=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an class=3D"o"><span style=3D"color: #660;" class=3D"styled-by-prettify">&l=
t;<</span></span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span class=3D"s"><span style=3D"color: #080;" class=3D"styled-b=
y-prettify">":</span></span><span class=3D"se"><span style=3D"color: #080;"=
class=3D"styled-by-prettify">\t</span></span><span class=3D"s"><span style=
=3D"color: #080;" class=3D"styled-by-prettify">body"</span></span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span class=3D"o">=
<span style=3D"color: #660;" class=3D"styled-by-prettify"><<</span></=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n class=3D"n"><span style=3D"color: #000;" class=3D"styled-by-prettify">end=
l</span></span><span class=3D"p"><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">;</span></span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"><br> </span><span class=3D"n"><span style=3D"col=
or: #000;" class=3D"styled-by-prettify">cout</span></span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span class=3D"o"><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify"><<</span></span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span class=
=3D"n"><span style=3D"color: #000;" class=3D"styled-by-prettify">bar</span>=
</span><span class=3D"p"><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">(</span></span><span class=3D"n"><span style=3D"color: #000;" class=
=3D"styled-by-prettify">i</span></span><span class=3D"p"><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">)</span></span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span class=3D"o"><span style=
=3D"color: #660;" class=3D"styled-by-prettify"><<</span></span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span class=3D"=
s"><span style=3D"color: #080;" class=3D"styled-by-prettify">":</span></spa=
n><span class=3D"se"><span style=3D"color: #080;" class=3D"styled-by-pretti=
fy">\t</span></span><span class=3D"s"><span style=3D"color: #080;" class=3D=
"styled-by-prettify">end"</span></span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span class=3D"o"><span style=3D"color: #66=
0;" class=3D"styled-by-prettify"><<</span></span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span class=3D"n"><span style=
=3D"color: #000;" class=3D"styled-by-prettify">endl</span></span><span clas=
s=3D"p"><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br> =
</span><span class=3D"k"><span style=3D"color: #008;" class=3D"style=
d-by-prettify">return</span></span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span class=3D"n"><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">i</span></span><span class=3D"o"><span style=3D"=
color: #660;" class=3D"styled-by-prettify">*</span></span><span class=3D"mi=
"><span style=3D"color: #066;" class=3D"styled-by-prettify">1000</span></sp=
an><span class=3D"p"><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">;</span></span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"><br></span><span class=3D"p"><span style=3D"color: #660;" class=3D"styled=
-by-prettify">}</span></span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br><br></span><span class=3D"kt"><span style=3D"color: #008;" =
class=3D"styled-by-prettify">void</span></span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"> </span><span class=3D"nf"><span style=3D"col=
or: #000;" class=3D"styled-by-prettify">async_user_handler</span></span><sp=
an class=3D"p"><span style=3D"color: #660;" class=3D"styled-by-prettify">()=
</span></span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
></span><span class=3D"p"><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">{</span></span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br> </span><span class=3D"n"><span style=3D"color: #00=
0;" class=3D"styled-by-prettify">vector</span></span><span class=3D"o"><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify"><</span></span><sp=
an class=3D"n"><span style=3D"color: #000;" class=3D"styled-by-prettify">fu=
ture</span></span><span class=3D"o"><span style=3D"color: #080;" class=3D"s=
tyled-by-prettify"><</span></span><span class=3D"kt"><span style=3D"colo=
r: #080;" class=3D"styled-by-prettify">int</span></span><span class=3D"o"><=
span style=3D"color: #080;" class=3D"styled-by-prettify">></span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">></span></span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span class=3D"=
n"><span style=3D"color: #000;" class=3D"styled-by-prettify">fs</span></spa=
n><span class=3D"p"><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">;</span></span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
><br><br> </span><span class=3D"c1"><span style=3D"color: #800=
;" class=3D"styled-by-prettify">// instead of `async` at function signature=
, `asynchronous` should be</span></span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br> </span><span class=3D"c1"><span s=
tyle=3D"color: #800;" class=3D"styled-by-prettify">// used at the call plac=
e:</span></span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br> </span><span class=3D"k"><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">for</span></span><span class=3D"p"><span style=3D"=
color: #660;" class=3D"styled-by-prettify">(</span></span><span class=3D"k"=
><span style=3D"color: #008;" class=3D"styled-by-prettify">auto</span></spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span c=
lass=3D"n"><span style=3D"color: #000;" class=3D"styled-by-prettify">i</spa=
n></span><span class=3D"o"><span style=3D"color: #660;" class=3D"styled-by-=
prettify">=3D</span></span><span class=3D"mi"><span style=3D"color: #066;" =
class=3D"styled-by-prettify">0</span></span><span class=3D"p"><span style=
=3D"color: #660;" class=3D"styled-by-prettify">;</span></span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span class=3D"n"><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify">i</span></span><spa=
n class=3D"o"><span style=3D"color: #660;" class=3D"styled-by-prettify">!=
=3D</span></span><span class=3D"mi"><span style=3D"color: #066;" class=3D"s=
tyled-by-prettify">5</span></span><span class=3D"p"><span style=3D"color: #=
660;" class=3D"styled-by-prettify">;</span></span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span class=3D"o"><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">++</span></span><span class=3D"n"=
><span style=3D"color: #000;" class=3D"styled-by-prettify">i</span></span><=
span class=3D"p"><span style=3D"color: #660;" class=3D"styled-by-prettify">=
)</span></span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r> </span><span class=3D"n"><span style=3D"color=
: #000;" class=3D"styled-by-prettify">fs</span></span><span class=3D"p"><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">.</span></span><span=
class=3D"n"><span style=3D"color: #000;" class=3D"styled-by-prettify">push=
_back</span></span><span class=3D"p"><span style=3D"color: #660;" class=3D"=
styled-by-prettify">(</span></span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span class=3D"n"><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">asynchronous</span></span><span class=3D"p"><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">([</span></span><span=
class=3D"n"><span style=3D"color: #000;" class=3D"styled-by-prettify">i</s=
pan></span><span class=3D"p"><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">]{</span></span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span class=3D"k"><span style=3D"color: #008;" class=3D"=
styled-by-prettify">return</span></span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span class=3D"n"><span style=3D"color: #00=
0;" class=3D"styled-by-prettify">foo</span></span><span class=3D"p"><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">(</span></span><span cla=
ss=3D"n"><span style=3D"color: #000;" class=3D"styled-by-prettify">i</span>=
</span><span class=3D"o"><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">+</span></span><span class=3D"mi"><span style=3D"color: #066;" clas=
s=3D"styled-by-prettify">1</span></span><span class=3D"p"><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">);</span></span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span class=3D"p"><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">})</span></span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span class=3D"p"><=
span style=3D"color: #660;" class=3D"styled-by-prettify">);</span></span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br><br> &nbs=
p; </span><span class=3D"k"><span style=3D"color: #008;" class=3D"styled-by=
-prettify">for</span></span><span class=3D"p"><span style=3D"color: #660;" =
class=3D"styled-by-prettify">(</span></span><span class=3D"k"><span style=
=3D"color: #008;" class=3D"styled-by-prettify">auto</span></span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span class=3D"o"><=
span style=3D"color: #660;" class=3D"styled-by-prettify">&&</span><=
/span><span class=3D"n"><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify">f</span></span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span class=3D"o"><span style=3D"color: #660;" class=3D"styled=
-by-prettify">:</span></span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span class=3D"n"><span style=3D"color: #000;" class=3D=
"styled-by-prettify">fs</span></span><span class=3D"p"><span style=3D"color=
: #660;" class=3D"styled-by-prettify">)</span></span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"><br> </span>=
<span class=3D"n"><span style=3D"color: #000;" class=3D"styled-by-prettify"=
>cout</span></span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> </span><span class=3D"o"><span style=3D"color: #660;" class=3D"styled-by=
-prettify"><<</span></span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span class=3D"n"><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify">await</span></span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><span class=3D"n"><span style=3D"color: =
#000;" class=3D"styled-by-prettify">f</span></span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span class=3D"o"><span style=3D"=
color: #660;" class=3D"styled-by-prettify"><<</span></span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span class=3D"s"><=
span style=3D"color: #080;" class=3D"styled-by-prettify">":</span></span><s=
pan class=3D"se"><span style=3D"color: #080;" class=3D"styled-by-prettify">=
\t</span></span><span class=3D"s"><span style=3D"color: #080;" class=3D"sty=
led-by-prettify">after end"</span></span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span class=3D"o"><span style=3D"color: #66=
0;" class=3D"styled-by-prettify"><<</span></span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span class=3D"n"><span style=
=3D"color: #000;" class=3D"styled-by-prettify">endl</span></span><span clas=
s=3D"p"><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span>=
<span class=3D"p"><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>}</span></span></pre></div></code></div><br>P.S. Stackful and stackless co=
routines have some overlap in use cases, both have unique advantages and di=
sadvantages. N3858 tries to allow both to be used as underlying implementat=
ion, killing all unique advantages and bringing all unique disadvantages of=
stackless and stackfull coroutines.<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" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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_4770_5899507.1390945814954--
.
Author: Bjorn Reese <breese@mail1.stofanet.dk>
Date: Fri, 31 Jan 2014 10:42:24 +0100
Raw View
On 01/28/2014 10:50 PM, Evgeny Panasyuk wrote:
> Stackful coroutines can be implemented in library form, just like
> std::thread. There is no need to introduce new special kind of
> functions. There is no need to limit await to "one level".
> There is ready library implementation of stackful coroutines -
> Boost.Coroutine
> http://www.boost.org/doc/libs/1_55_0/libs/coroutine/doc/html/index.html.
See also N3708 "A proposal to add coroutines to the C++ standard
library"
http://isocpp.org/files/papers/n3708.pdf
--
---
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/.
.