220 21914 <CA+wfc1-s0_TZUn_FcoPnEFTOiofM8oLwdy_4EWDmtK+wApratw@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 12:44:43 +0200
Lines: 181
Approved: news@gmane.org
Message-ID: <CA+wfc1-s0_TZUn_FcoPnEFTOiofM8oLwdy_4EWDmtK+wApratw@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>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=089e015383e818e0ed05229b123b
X-Trace: ger.gmane.org 1445424308 1524 80.91.229.3 (21 Oct 2015 10:45:08 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 21 Oct 2015 10:45:08 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCLZHP5J7MHRBLWZTWYQKGQECPDKVSY@isocpp.org Wed Oct 21 12:45:07 2015
Return-path: <std-proposals+bncBCLZHP5J7MHRBLWZTWYQKGQECPDKVSY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pa0-f69.google.com ([209.85.220.69])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCLZHP5J7MHRBLWZTWYQKGQECPDKVSY@isocpp.org>)
	id 1ZoqtE-0001sq-S3
	for gclcip-std-proposals@m.gmane.org; Wed, 21 Oct 2015 12:45:05 +0200
Original-Received: by padda3 with SMTP id da3sf15351738pad.0
        for <gclcip-std-proposals@m.gmane.org>; Wed, 21 Oct 2015 03:45:03 -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=dBuLhrke8WpuaQ5MAQ2uDMaMgYuzWEr3NPPRE+Wb+RE=;
        b=NfJxImESAXMsb1Bk7ne+brjk/05ebf24+jDtIJs+5ZzQR5g5nsLjRCXQhIRCJuG6BF
         13cFCVYuZCL4jzs7cPeYugAy7sP8xh/ETvx2DsRLL53ajeK+zkMgV6XPqsaN5xKVkzb0
         b3GDeyNsMLbj1g/yu+X0QYV6x32U/CGizrdvLe9RIhCammFuLLrG59bRt8Prz87OKfpr
         WRPOEgFeT9k58PXpaj3Aw8Ke76vvmtB/wqz3vnPvOpUqOhW7CCpqdiJSZA35Bx7twncQ
         uR0asAHhhIrIMHOAqm/c2kuMFtGSqQP78/g5xFrlfg7aflayoVEb9tZLZ11161ejM+9S
         BYHA==
X-Gm-Message-State: ALoCoQmkOXEOgCr8MUJijJpy/590CqiQnG7dIXqkVmdPiaweclyxYVX7LSKT4gnrPSLPZRkKd7Tq
X-Received: by 10.66.137.43 with SMTP id qf11mr6960135pab.1.1445424303744;
        Wed, 21 Oct 2015 03:45:03 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.182.81.33 with SMTP id w1ls398690obx.68.gmail; Wed, 21 Oct
 2015 03:45:02 -0700 (PDT)
X-Received: by 10.202.63.212 with SMTP id m203mr5259608oia.15.1445424302717;
        Wed, 21 Oct 2015 03:45:02 -0700 (PDT)
Original-Received: from mail-ob0-x229.google.com (mail-ob0-x229.google.com. [2607:f8b0:4003:c01::229])
        by mx.google.com with ESMTPS id p67si4871829oib.97.2015.10.21.03.45.02
        for <std-proposals@isocpp.org>
        (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Wed, 21 Oct 2015 03:45:02 -0700 (PDT)
Received-SPF: pass (google.com: domain of oliver.kowalke@gmail.com designates 2607:f8b0:4003:c01::229 as permitted sender) client-ip=2607:f8b0:4003:c01::229;
Original-Received: by obbwb3 with SMTP id wb3so37531743obb.0
        for <std-proposals@isocpp.org>; Wed, 21 Oct 2015 03:45:02 -0700 (PDT)
X-Received: by 10.182.191.38 with SMTP id gv6mr5307286obc.7.1445424302447;
 Wed, 21 Oct 2015 03:45:02 -0700 (PDT)
Original-Received: by 10.76.71.233 with HTTP; Wed, 21 Oct 2015 03:44:43 -0700 (PDT)
In-Reply-To: <d7653631-b45c-4952-a308-9919e84c538e@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::229 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:21914
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/21914>

--089e015383e818e0ed05229b123b
Content-Type: text/plain; charset=UTF-8

2015-10-21 11:09 GMT+02:00 Giovanni Piero Deretta <gpderetta@gmail.com>:

> if you refer to class execution_context from boost.context - it allows to
>> pass data through a context switch.
>>
>
> to be clear, I meant the execution_context as described in P0099R0. I just
> reread it and as far as I can tell doesn't have a native facility for
> parameter passing. I believe this is an important functionality, and the
> switching primitive should at least allow passing a void* through.
>

yes, P0099R0 does not reflect this change - working on boost.fiber I
encountered the need for passing parameters through the context switch.
I added this functionality to boost.context - at the moment only of type
void pointer.


>
>
>> execution_context::current() is a thread-local, local static pointer to a
>> execution_context.
>> P0099R1 will probably reflect this.
>>
>
> I still do not see what's the use case for current(). In a way it is a
> wrong concept: an execution_context captures the state of an *halted*
> thread of execution, so there is no valid execution_context state for the
> currently running thread of execution.
>

for me, an execution context consits out of a stack and a set of CPU
registers (stack pointer, instruction pointer, some other registers defined
by the ABI).
if you start/enter main() or start/enter a thread (thread-fn) you already
have an execution context. You need a way to access this context.
Especially in teh case of userland-threads/fibers the main
execution-context can be handled as a fiber too. that's the case for
boost.fiber were the main context (running main())
is handled as the other threads (no difference). That means I need a way to
assign and access the main context. Without execution_context:current()
I would need to hold and pass the current context to each place where it is
need.
For instance you can run a fiber (from boost.fiber) and executing
coroutines from boost.coroutine2. both access the same current
execution_context.
Another example, boost.fiber allows directly call
boost::this_fiber::yiled() in main() without to invoke any initialization
functionality directly.


>
>
>>  sure that the simple context switch will take < 10 CPU cycles - but you
>> need some maintenance code to
>>
>>
> what maintenance code exactly? I've just looked at boost.context
> implementation and the operator() seems pretty minimal.
>

the context switch using jump_fcontext() takes < 10 CPU cycles, while
execution_context::operator() need more cycles because it has to update TLS.


> My "fast" context switching implementation uses GCC inline assembly and a
> large list of clobbered registers so that the switching code itself does
> not need to conservatively save and restore all callee saved registers; The
> code works and is fast, but it is tricky and flaky (I would not recommend
> it for a pure library implementation, depending on the version, GCC might
> not like the large clobber list and you tend to hit dark corners of the
> optimiser) but it shows that with compiler help context switch does not
> need to be slow.
>

yes, but boost.context was required to support a broad range of compilers
and unfortunately MS decided to drop inline assembler for 64Bit MS VC.

-- 

--- 
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/.

--089e015383e818e0ed05229b123b
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 11:09 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:0 0 0 .8ex;=
border-left:1px #ccc solid;padding-left:1ex"><span class=3D""><blockquote c=
lass=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #c=
cc solid;padding-left:1ex"><div dir=3D"ltr"><div><div class=3D"gmail_quote"=
><div>if you refer to class execution_context from boost.context - it allow=
s to pass data through a context switch.<br></div></div></div></div></block=
quote></span><div><br>to be clear, I meant the execution_context as describ=
ed in P0099R0. I just reread it and as far as I can tell doesn&#39;t have a=
 native facility for parameter passing. I believe this is an important func=
tionality, and the switching primitive should at least allow passing a void=
* through.<br></div></blockquote><div><br></div><div>yes, P0099R0 does not =
reflect this change - working on boost.fiber I encountered the need for pas=
sing parameters through the context switch.<br></div><div>I added this func=
tionality to boost.context - at the moment only of type void pointer.<br></=
div><div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 =
0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>=C2=A0</div><span =
class=3D""><blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:=
0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><d=
iv class=3D"gmail_quote"><div></div><div>execution_context::current() is a =
thread-local, local static pointer to a execution_context.<br></div><div>P0=
099R1 will probably reflect this.<br></div></div></div></div></blockquote><=
/span><div><br>I still do not see what&#39;s the use case for current(). In=
 a way it is a wrong concept: an execution_context captures the state of an=
 *halted* thread of execution, so there is no valid execution_context state=
 for the currently running thread of execution.<br></div></blockquote><br><=
/div><div class=3D"gmail_quote">for me, an execution context consits out of=
 a stack and a set of CPU registers (stack pointer, instruction pointer, so=
me other registers defined by the ABI).<br></div><div class=3D"gmail_quote"=
>if you start/enter main() or start/enter a thread (thread-fn) you already =
have an execution context. You need a way to access this context.<br></div>=
<div class=3D"gmail_quote">Especially in teh case of userland-threads/fiber=
s the main execution-context can be handled as a fiber too. that&#39;s the =
case for boost.fiber were the main context (running main())<br></div><div c=
lass=3D"gmail_quote">is handled as the other threads (no difference). That =
means I need a way to assign and access the main context. Without execution=
_context:current()<br></div><div class=3D"gmail_quote">I would need to hold=
 and pass the current context to each place where it is need.<br></div><div=
 class=3D"gmail_quote">For instance you can run a fiber (from boost.fiber) =
and executing coroutines from boost.coroutine2. both access the same curren=
t execution_context.<br></div><div class=3D"gmail_quote">Another example, b=
oost.fiber allows directly call boost::this_fiber::yiled() in main() withou=
t to invoke any initialization functionality directly.<br></div><div class=
=3D"gmail_quote"><div>=C2=A0</div><blockquote class=3D"gmail_quote" style=
=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>=C2=
=A0</div><span class=3D""><blockquote class=3D"gmail_quote" style=3D"margin=
:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=
=3D"ltr"><div><div class=3D"gmail_quote"><div>=C2=A0sure that the simple co=
ntext switch will take &lt; 10 CPU cycles - but you need some maintenance c=
ode to</div></div><br></div></div></blockquote></span><div><br>what mainten=
ance code exactly? I&#39;ve just looked at boost.context implementation and=
 the operator() seems pretty minimal.<br></div></blockquote><div><br></div>=
<div>the context switch using jump_fcontext() takes &lt; 10 CPU cycles, whi=
le execution_context::operator() need more cycles because it has to update =
TLS.<br></div><div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"m=
argin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>My &quot=
;fast&quot; context switching implementation uses GCC inline assembly and a=
 large list of clobbered registers so that the switching code itself does n=
ot need to conservatively save and restore all callee saved registers; The =
code works and is fast, but it is tricky and flaky (I would not recommend i=
t for a pure library implementation, depending on the version, GCC might no=
t like the large clobber list and you tend to hit dark corners of the optim=
iser) but it shows that with compiler help context switch does not need to =
be slow.<br></div></blockquote></div><br></div><div class=3D"gmail_extra">y=
es, but boost.context was required to support a broad range of compilers an=
d unfortunately MS decided to drop inline assembler for 64Bit MS VC.<br></d=
iv></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 />

--089e015383e818e0ed05229b123b--

.
