CppCon 2016: James McNellis “Introduction to C++ Coroutines"

Поділитися
Вставка
  • Опубліковано 10 січ 2025

КОМЕНТАРІ • 48

  • @JunZhang-ralphjzhang
    @JunZhang-ralphjzhang 9 місяців тому +3

    The year is 2024, and this is still one of the clearest talks about coroutines so far!

  • @dannix84
    @dannix84 2 роки тому +10

    The year is 2022, and this is still one of the clearest talks about coroutines so far!

  • @dexterman6361
    @dexterman6361 2 роки тому +5

    The year is 2023, and this is the best co-routines talk I've seen so far. I will update this comment if I find something else

  • @SamWhitlock
    @SamWhitlock 3 роки тому +26

    The year is 2021, and this is still one of the clearest talks about coroutines so far!

    • @ru2979
      @ru2979 2 роки тому +1

      can u please suggest some other good ones please...

    • @aldrinaldrin4618
      @aldrinaldrin4618 Рік тому

      It's not clear to me what's it referring when he said "suspend", what's actually being suspended here?

  • @ManuAnand79
    @ManuAnand79 3 роки тому +16

    Not sure why this talk isn't more popular. As other folks mentioned, this really is the best description of coroutines.

  • @debashishdeka4271
    @debashishdeka4271 4 роки тому +7

    One of the best talks on cpp co routine.

  • @xealit
    @xealit 4 місяці тому

    Excellent talk 👏

  • @JiveDadson
    @JiveDadson 6 років тому +4

    Can someone provide a link to the talk "later this afternoon"? 38:03

    • @aryangupta9034
      @aryangupta9034 5 років тому +9

      Maybe a little late, but for future watchers: ua-cam.com/video/v0SjumbIips/v-deo.html

  • @HiAdrian
    @HiAdrian 7 років тому +1

    4:18 _state->conn_ is not declared anywhere.

  • @yufengjiang4138
    @yufengjiang4138 3 роки тому

    At 4:00, is do_while function a recursive function?

  • @comradepeter87
    @comradepeter87 3 роки тому +2

    8:00 I thought this was a trick question and this was a variable declaration 🤣

  • @Qizot
    @Qizot 6 років тому

    This talk look alike to CppCon 2015: Gor Nishanov “C++ Coroutines - a negative overhead abstraction"

  • @MaceUA
    @MaceUA 3 роки тому

    I think the slide with resumable_thing& operator=(resumable_thing&& other) (19:06) has a bug. Correct code should also check whether this->_coroutine and other._coroutine are different, and, if they are, destroy the old this->_coroutine before assigning the handle. Otherwise the code like this would leak memory and other resources:
    resumable_thing first_counter = counter();
    resumable_thing second_counter = counter();
    first_counter = std::move(second_counter); // leak of the original first_counter coroutine

    • @MaceUA
      @MaceUA 3 роки тому +1

      Though, to be honest, this is quite a contrived example. Yet the proposed operator= from the slide is not fully correct.
      I'd prefer to =delete it instead of implementing. Having a move constructor without operator= should be enough for almost all normal use cases.

  • @mrdwz
    @mrdwz 4 роки тому

    Why in the “let‘s look at future…” co_await after override that returns an awaiter can still be assigned to int?

  • @shadowmil
    @shadowmil 8 років тому +6

    Instead of co_await and co_return, why not "await' and 'yield'?

    • @JiveDadson
      @JiveDadson 6 років тому +6

      That would break any code that uses _await_ or _yield_ as an identifier. It would also be less obvious that the routine is a coroutine rather than the garden-variety kind.

    • @MrGerdbrecht
      @MrGerdbrecht 6 років тому

      Dont yield() the world man.

    • @MrGerdbrecht
      @MrGerdbrecht 6 років тому

      Instead of co_await why not co_await_and_while_waiting_hit_a_noob

  • @markf5931
    @markf5931 2 роки тому

    In his slides did he miss defining the method resumable_thing::resume() which should call the coroutine_handle::resume()?

    • @OptimusVlad
      @OptimusVlad 2 роки тому

      Yes, he did. He should have called that function something else, like my_resume(), to make it clear that you're not calling the coroutine_handle's resume() function directly.

  • @sahilsingh1
    @sahilsingh1 8 років тому +1

    Is a corouting same as Python functions using yield keyword ?

    • @Omnifarious0
      @Omnifarious0 7 років тому +3

      Yes, one application of them is Python-style generators.

  • @MegaBrownee
    @MegaBrownee 8 років тому +3

    Am I crazy in thinking this could replace classes? If not in C++, in some other llvm-based language? One could merge the constructor body and the class definition. Think about it: they're converting function local/"stack" variables into struct fields. Why not have "classes" that are entirely coroutine ctors? Static members remain function static vars. Nest the coroutines inside a namespace for appropriate lexical scoping. At that point, you come awful close to unifying classes/structs, namespaces, and blocks.
    Beside the crazy idea above, coroutines could make passing "lazy" parameters simple--a parameter where the function body gets to decide if and when to evaluate an argument, rather than eagerly evaluating all parameters before entering the body. This enables writing functions with short-circuiting, like `if...then`. rather than clunky approaches like passing a callable object and a list of args or a struct, or using mind-numbingly verbose patterns like visitor.
    Imagine what you could do in `std::for_each` situations if you could do all this on fly with very low ceremony. I actually think cheap coroutines are going to be bigger than anyone gives credit, especially if built into the innards of llvm and gcc, and able to do heap elision like discussed.

    • @tz3721
      @tz3721 2 роки тому +1

      It's common in Javascript. Everything in the local function scopre is private, and then a associative array of functions is returned to become the public interface.

    • @ZeroPlayerGame
      @ZeroPlayerGame 2 роки тому

      Not that crazy, closures and objects are really more or less the same thing

  • @andrey7268
    @andrey7268 8 років тому +1

    This resumable_thing is awfully similar to std::future. Why the duplication?

    • @tobiasfuchs7016
      @tobiasfuchs7016 8 років тому

      This article gives some good explanations:
      meetingcpp.com/index.php/br/items/resumable-functions-async-and-await.html
      Yes, there is a hype for coroutines, we will see if they live up to it. The standard committee is not known for hasty changes to the C++ language, so no need to worry.

  • @iddn
    @iddn 8 років тому +6

    I can't help but feel these will not live up to the hype

    • @Omnifarious0
      @Omnifarious0 7 років тому +6

      I've implemented at least two Open Source frameworks that attempt to make asynchronous code easier to write. Both are possibly more confusing than callbacks. But callbacks are really awful as they force you to break up an ordinary control flow in some very unintuitive ways that make your code a lot harder to read and understand.
      And threads are too much overhead both in OS resources and in terms of how much synchronization code you're suddenly forced to add to your code. And that synchronization code oftentimes has a significant performance cost as well.
      So, co-routines are a really great idea, and they're long, long overdue.

  • @__hannibaalbarca__
    @__hannibaalbarca__ 2 роки тому

    Co-Routine should be programmed by c/c++ as skill programmer; like this every think in library and we ‘should follow you’ instead to looking for best solutions for every program, algorithm, software…
    Over-Library-Zation will kill c/c++.

  • @khatharrmalkavian3306
    @khatharrmalkavian3306 3 роки тому +3

    Well that's disgusting. I feel like it would be better to not have coroutines yet than to have this.

  • @morezco
    @morezco 8 років тому +3

    Learned VB and C# and had a lot of fun. Opened a CPP file to try and edit it and I can't make it even print my bloody name, so YT classes please save me.

    • @PhilippeCarphin
      @PhilippeCarphin 8 років тому +10

      #include
      int main(int argc, char *argv[])
      {
      std::cout "Guilherme Moresco"

    • @shadowwalker23901
      @shadowwalker23901 7 років тому +8

      the good news is in en.cppreference.com/w/cpp/language/main_function the unused argc and argv is not needed and return 0 can be implied.
      #include
      int main() {
      std::cout