Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #81591

Re: "C++20 Coroutines" by Martin Bond

From "Alf P. Steinbach" <alf.p.steinbach@gmail.com>
Newsgroups comp.lang.c++
Subject Re: "C++20 Coroutines" by Martin Bond
Date 2021-09-26 01:50 +0200
Organization A noiseless patient Spider
Message-ID <siocja$evj$1@dont-email.me> (permalink)
References <siauhc$mg6$1@dont-email.me> <sin7c5$c9d$1@dont-email.me> <sio33e$1248$1@gioia.aioe.org>

Show all headers | View raw


On 25 Sep 2021 23:07, Manfred wrote:
> On 9/25/2021 3:14 PM, Alf P. Steinbach wrote:
>> On 20 Sep 2021 23:30, Lynn McGuire wrote:
>>> "C++20 Coroutines" by Martin Bond
>>>     https://blog.feabhas.com/2021/09/c20-coroutines/
>>>
>>> "There seems to be a lot of confusion around the implementation of 
>>> C++20 coroutines, which I think is due to the draft technical 
>>> specification for C++20 stating that coroutines are a work in 
>>> progress so we can’t expect full compiler and library support at this 
>>> point in time.
>>> A lot of the problems probably arise from the lack of official 
>>> documentation about working with coroutines. We have been given C++ 
>>> syntax support for coroutines (the co_yield and co_return) but 
>>> without all of what I consider full library support. The standard 
>>> library has hooks and basic functionality for supporting coroutines, 
>>> but we must incorporate this into our own classes. I anticipate that 
>>> there will be full library support for generator style coroutines in 
>>> C++23."
>>
>> The main confusion about C++20 “coroutines” is that they're general 
>> coroutines.
>>
>> They're not: they're simple continuations, the special case of 
>> /stackless/ coroutines (no dedicated stack for each coroutine).
>>
>> While that's nice performance-wise it's very limited, and the 
>> Microsoft style support framework adopted in C++20 requires you to 
>> build a full fledged star ship in order to lift a little pebble; it's, 
>> well, moronic.
>>
>> ---
>>
>> I once started coding up real coroutines in terms of standard C++ 
>> threads.
>>
>> That could be very useful, in contrast to the mostly useless C++17 
>> continuations.
>>
>> However, I stopped fiddling with it when the complexity of the 
>> implementation overwhelmed me. No doubt because of a lack of 
>> experience in safe multi-tasking. It would be really nice if SOMEONE 
>> could do this: real general coroutines, by leveraging real C++ threads.
>>
>> ---
>>
>> That could open the world of safe multi-tasking to C++ programmers in 
>> general.
> 
> I'm no expert in coroutines, but AFAIU their main advantage is to enable 
> multitasking without the overhead of multithreading.

What you write is an advantage of continuations compared to general 
coroutines. I consider that a very marginal advantage. Correctness is 
far, far more important than some micro-efficiency.

The advantage of general coroutines is that they enable multi-tasking 
(namely cooperative multi-tasking) without the severe synchronization 
problems of general threads or processes.

Coroutines don't automagically deal with all kinds of multi-tasking 
problems, in particular deadlocks are still possible, but you don't have 
two or more threads possibly accessing the same thing at a time, since 
only one coroutine executes at a time.


> In order to achieve this, language support is needed that was just not 
> available prior to C++20 (and even with C++20 such support is limited, 
> so that only the subset of continuations is actually available, as you say)

True, but I fail to see any reason, and I haven't yet seen anybody able 
to cough up a reason, to have continuations in C++.


> The point being, if you try to do that using threads kind of defeats the 
> purpose, doesn't it?

No (you misunderstood the purpose).

Doing this could open the world of safe multi-tasking to C++ programmers 
in general.

Oh, I already wrote that, sorry.


> (even if you build this with full synchronization inside, you'll still 
> pay the price of performance and resource usage, which can be relevant 
> for this kind of thing)

Yes, it must be built with synchronization inside, and like threads each 
general coroutine needs its own stack, which is another cost: firing up 
a general coroutine generally involves a dynamic allocation (though I 
guess with language support it's technically possible to use statically 
allocated stack areas when the number of coroutines has a reasonably low 
upper bound, but such support would be needed for that because standard 
threads don't provide any means to influence the per-thread stacks).


>> Another such enabler: an implementation of Ada-like rendezvous.
>>
>> And, and, ... Occam-like channels, maybe. :)

I forgot to mention Linda.

Oh well.


- Alf

Back to comp.lang.c++ | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

"C++20 Coroutines" by Martin Bond Lynn McGuire <lynnmcguire5@gmail.com> - 2021-09-20 16:30 -0500
  Re: "C++20 Coroutines" by Martin Bond Bo Persson <bo@bo-persson.se> - 2021-09-21 09:28 +0200
  Re: "C++20 Coroutines" by Martin Bond Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-21 11:45 +0200
    Re: "C++20 Coroutines" by Martin Bond HorseyWorsey@the_stables.com - 2021-09-21 15:37 +0000
      Re: "C++20 Coroutines" by Martin Bond Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-21 17:40 +0200
      Re: "C++20 Coroutines" by Martin Bond Juha Nieminen <nospam@thanks.invalid> - 2021-09-22 05:22 +0000
        Re: "C++20 Coroutines" by Martin Bond HorseyWorsey@the_stables.com - 2021-09-22 09:26 +0000
          Re: "C++20 Coroutines" by Martin Bond Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-22 16:40 +0200
            Re: "C++20 Coroutines" by Martin Bond HorseyWorsey@the_stables.com - 2021-09-22 15:01 +0000
              Re: "C++20 Coroutines" by Martin Bond Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-23 05:38 +0200
                Re: "C++20 Coroutines" by Martin Bond Branimir Maksimovic <branimir.maksimovic@gmail.com> - 2021-09-23 09:05 +0000
                Re: "C++20 Coroutines" by Martin Bond Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-24 18:15 +0200
                Re: "C++20 Coroutines" by Martin Bond Branimir Maksimovic <branimir.maksimovic@gmail.com> - 2021-09-25 00:57 +0000
                Re: "C++20 Coroutines" by Martin Bond HorseyWorsey@the_stables.com - 2021-09-23 09:11 +0000
                Re: "C++20 Coroutines" by Martin Bond Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-24 18:17 +0200
                Re: "C++20 Coroutines" by Martin Bond HorseyWorsey@the_stables.com - 2021-09-25 09:19 +0000
                Re: "C++20 Coroutines" by Martin Bond Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-25 12:00 +0200
                Re: "C++20 Coroutines" by Martin Bond HorseyWorsey@the_stables.com - 2021-09-25 10:09 +0000
                Re: "C++20 Coroutines" by Martin Bond Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-25 12:18 +0200
                Re: "C++20 Coroutines" by Martin Bond HorseyWorsey@the_stables.com - 2021-09-25 10:39 +0000
                Re: "C++20 Coroutines" by Martin Bond Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-25 12:42 +0200
                Re: "C++20 Coroutines" by Martin Bond HorseyWorsey@the_stables.com - 2021-09-25 10:44 +0000
                Re: "C++20 Coroutines" by Martin Bond Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-25 13:14 +0200
                Re: "C++20 Coroutines" by Martin Bond Branimir Maksimovic <branimir.maksimovic@gmail.com> - 2021-09-25 12:44 +0000
                Re: "C++20 Coroutines" by Martin Bond Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-25 15:58 +0200
                Re: "C++20 Coroutines" by Martin Bond Branimir Maksimovic <branimir.maksimovic@gmail.com> - 2021-09-25 13:59 +0000
                Re: "C++20 Coroutines" by Martin Bond Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-25 16:23 +0200
                Re: "C++20 Coroutines" by Martin Bond Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-28 07:24 +0200
                Re: "C++20 Coroutines" by Martin Bond HorseyWorsey@the_stables.com - 2021-09-25 15:28 +0000
                Re: "C++20 Coroutines" by Martin Bond HorseyWorsey@the_stables.com - 2021-09-25 15:04 +0000
                Re: "C++20 Coroutines" by Martin Bond Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-25 18:44 +0200
                Re: "C++20 Coroutines" by Martin Bond HorseyWorsey@the_stables.com - 2021-09-26 14:15 +0000
                Re: "C++20 Coroutines" by Martin Bond Branimir Maksimovic <branimir.maksimovic@gmail.com> - 2021-09-25 12:32 +0000
          Re: "C++20 Coroutines" by Martin Bond Juha Nieminen <nospam@thanks.invalid> - 2021-09-23 07:42 +0000
            Re: "C++20 Coroutines" by Martin Bond HorseyWorsey@the_stables.com - 2021-09-23 09:14 +0000
              Re: "C++20 Coroutines" by Martin Bond Juha Nieminen <nospam@thanks.invalid> - 2021-09-24 04:42 +0000
            Re: "C++20 Coroutines" by Martin Bond Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-24 18:19 +0200
              Re: "C++20 Coroutines" by Martin Bond Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-09-24 21:07 +0100
                Re: "C++20 Coroutines" by Martin Bond Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-10-06 13:19 -0700
              Re: "C++20 Coroutines" by Martin Bond Branimir Maksimovic <branimir.maksimovic@gmail.com> - 2021-09-25 00:58 +0000
                Re: "C++20 Coroutines" by Martin Bond Juha Nieminen <nospam@thanks.invalid> - 2021-09-27 05:39 +0000
                Re: "C++20 Coroutines" by Martin Bond Branimir Maksimovic <branimir.maksimovic@gmail.com> - 2021-09-29 02:30 +0000
              Re: "C++20 Coroutines" by Martin Bond HorseyWorsey@the_stables.com - 2021-09-25 09:20 +0000
        Re: "C++20 Coroutines" by Martin Bond "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2021-09-22 11:31 +0200
      Re: "C++20 Coroutines" by Martin Bond Sam <sam@email-scan.com> - 2021-09-22 18:43 -0400
        Re: "C++20 Coroutines" by Martin Bond Juha Nieminen <nospam@thanks.invalid> - 2021-09-23 07:45 +0000
          Re: "C++20 Coroutines" by Martin Bond "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-09-23 01:53 -0700
          Re: "C++20 Coroutines" by Martin Bond Sam <sam@email-scan.com> - 2021-09-24 19:21 -0400
            Re: "C++20 Coroutines" by Martin Bond HorseyWorsey@the_stables.com - 2021-09-25 09:28 +0000
              Re: "C++20 Coroutines" by Martin Bond Branimir Maksimovic <branimir.maksimovic@gmail.com> - 2021-09-25 12:38 +0000
            Re: "C++20 Coroutines" by Martin Bond Juha Nieminen <nospam@thanks.invalid> - 2021-09-27 05:42 +0000
  Re: "C++20 Coroutines" by Martin Bond "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2021-09-25 15:14 +0200
    Re: "C++20 Coroutines" by Martin Bond Manfred <noname@add.invalid> - 2021-09-25 23:07 +0200
      Re: "C++20 Coroutines" by Martin Bond "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2021-09-26 01:50 +0200
        Re: "C++20 Coroutines" by Martin Bond Manfred <noname@add.invalid> - 2021-09-26 19:12 +0200

csiph-web