This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: For which gcc release is going to be foreseen the support for the Coroutines TS extension?


> On 20 Aug 2019, at 17:15, Florian Weimer <fweimer@redhat.com> wrote:
> 
> * Richard Biener:
> 
>> On August 20, 2019 5:19:33 PM GMT+02:00, Nathan Sidwell <nathan@acm.org> wrote:
>>> On 7/26/19 6:03 AM, Iain Sandoe wrote:
>>>> Hello Sebastian,
>>>> 
>>>>> On 26 Jul 2019, at 10:19, Florian Weimer <fweimer@redhat.com> wrote:
>>> 
>>>>> C++ coroutines are stackless.  I don't think any new low-level
>>> run-time
>>>>> support will be needed.
>>>> 
>>>> correct, C++20 coroutines and threading mechanisms are orthogonal
>>>> facilities; one can use (IS C++20) coroutines on top of a threaded
>>> system
>>>> or in a single-threaded environment.
>>>> 
>>>> Two places I see them as being a go-to facility in embedded systems
>>> are:
>>>>  * co-operative multi-tasking UIs on single-threaded platforms.
>>>>  * async I/O completion by continuations, rather than callbacks.
>>> 
>>> There are cases where the overhead of threads is too expensive.  For 
>>> instance hiding (cache-missing) load latencies by doing other work
>>> while 
>>> waiting -- a context switch at that point is far too expensive.
>> 
>> But are coroutines so much lower latency (and a context switch does
>> not involve cache misses on its own?). For doing useful work in this
>> context CPU designers invented SMT...
> 
> I think the idea is that you don't have to worry about synchronizing
> multiple threads to reap the benefits from hardware parallelism.  For
> hiding memory access latency, that could be important because the
> synchronization overhead could easily eat up any potential benefits.

It seems to me that this is another “tool” in the “toolbox”, and as such
will find use in more cases than the performance example given above.

Some uses might have more to do with code clarity than performance,
per se.

* e.g. any code that’s written in terms of a state machine, or as a large
body of callbacks, might prove to be a candidate for clearer representation
as coroutines.

* There’s a potentialy large reduction in held state for cases where the
processing is organised as a series of transformations (as the original 
motivating example was a compiler where it was inconvenient to produce
and consume that state between passes).

* There’s clearly an industry quest for a lighter weight representation than
threads and this is being driven (amongst others) by some of the largest
users of massively parallel systems - so SMT is not meeting all their needs.
Representatives from this group are saying that coroutines are part of the
solution that they want (and backing that up by sponsoring the language
development work and several compiler implementations).  I don’t have
visibility of their specific internal use-cases, of course, unfortunately.

* Avoiding recasting problems into a form suitable for overt multi-threading

* I expect (and already have one such person reporting bugs against my
branch) that the embedded (no threads) space will find this a clearer way
to implement some functionality (co-operative multitasking user interfaces
springs to mind as noted in a previous post).

I suppose that in the end we will not know how this tool is going to be used
until it gets wider exposure (although there are some production uses of
the LLVM implementation, it’s likely that people won’t commit heavily until
it’s in the standard).

0.02GBP only ..

Iain



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]