What is the difference between suspend-up and suspend-down coroutines?










2















The C++ community is currently discussing suspend-up vs suspend-down coroutines.



For example, suspend-down is mentioned in this proposal: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4453.pdf



What do these two terms mean?










share|improve this question


























    2















    The C++ community is currently discussing suspend-up vs suspend-down coroutines.



    For example, suspend-down is mentioned in this proposal: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4453.pdf



    What do these two terms mean?










    share|improve this question
























      2












      2








      2








      The C++ community is currently discussing suspend-up vs suspend-down coroutines.



      For example, suspend-down is mentioned in this proposal: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4453.pdf



      What do these two terms mean?










      share|improve this question














      The C++ community is currently discussing suspend-up vs suspend-down coroutines.



      For example, suspend-down is mentioned in this proposal: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4453.pdf



      What do these two terms mean?







      c++ coroutine






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 1:16









      sdgfsdhsdgfsdh

      8,20883995




      8,20883995






















          2 Answers
          2






          active

          oldest

          votes


















          3














          The terminology seems to be explained in p0099r1: "A low-level API for stackful context switching" which says:




          Notes on suspend-up and suspend-down terminology The terms suspend-up
          and suspend-down were introduced in paper N4232 2 and carried forward
          in P0158 9 to distinguish stackless ( suspend-up ) and stackful (
          suspend-down ) context switching. These terms rely on a particular
          visualization of the C++ function call operation in which calling a
          function passes control “downwards,” whereas returning from a function
          passes control “upwards.” The authors recommend the terms
          suspend-by-return instead of suspend-up , and suspend-by-call instead
          of
          suspend-down . The recommended terminology directly references the
          underlying C++ operations, without requiring a particular
          visualization.
          suspend-by-return ( suspend-up , or “stackless” context
          switching) is based on returning control from a called function to its
          caller, along with some indication as to whether the called function
          has completed and is returning a result or is merely suspending and
          expects to be called again. The called function’s body is coded in
          such a way that – if it suspended – calling it again will direct
          control to the point from which it last returned. This describes both
          P0057 6 resumable functions and earlier technologies such as
          Boost.Asio coroutines. 12
          suspend-by-call ( suspend-down, or
          “stackful” context switching) is based on calling a function which,
          transpar- ently to its caller, switches to some other logical chain of
          function activation records. (This may or may not be a contiguous
          stack area. The processor’s stack pointer register, if any, may or may
          not be involved.) This describes N4397 3 coroutines as well as
          Boost.Context, 13 Boost.Coroutine2 14 and Boost.Fiber. 15
          std::execution_context<>::operator()() requires suspend-by-call
          semantics.




          Both are old papers and is separate from p0057 which seems to be the main coroutines paper. p0444 discusses trying to unify these paper but does not seem to have gone anywhere. Also see Trip Report: C++ Standards Meeting in Issaquah, November 2016 which says:




          The Coroutines TS contains the co_await proposal, based on Microsoft’s original design.



          As mentioned previously, there are efforts underway to standardize a proposal for a different, stackful flavour of coroutines, as well as an exploratory effort to unify the two flavours under a common syntax. These proposals, however, are not currently slated to target the Coroutines TS. They may instead target a different TS (and if a unified syntax emerges, it could be that syntax, rather than the one in the Coroutines TS, that’s ultimately merged into the C++ standard).







          share|improve this answer

























          • Also relevant stackoverflow.com/questions/28977302/…

            – sdgfsdh
            Nov 14 '18 at 9:33


















          0














          each function creates a stack frame (reserves space on the stack for local variables etc.)



          suspend-up:



          • used by stackless context switching (coroutines...)

          • because you have only one stack (applications stack), you have to remove the stack frame of the suspended function (function of stackless coroutine)

          • otherwise other functions, executed after the coroutine has been suspended, would write their own stack frame and thus corrupt the stack frame of the suspended one

          • suspend-up == remove stack frame of suspended function == step some addresses at the stack upwards (for architectures where the stack grows from high to low addresses)

          suspend-down:



          • used by stackful context switching (coroutines, fibers, ...)

          • each coroutine/fiber gets their own stack, thus the application consist out of multiple stacks

          • if a stackful coroutine is suspended, the stack frame remains on the stack (because zhr stack is specific to/owned by the coroutine)

          • the stack pointer is simply changed to another stack (== switching to another stackful coroutine/fiber)

          • because the stack frame remains on the stack, it is called suspend-down





          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291812%2fwhat-is-the-difference-between-suspend-up-and-suspend-down-coroutines%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            3














            The terminology seems to be explained in p0099r1: "A low-level API for stackful context switching" which says:




            Notes on suspend-up and suspend-down terminology The terms suspend-up
            and suspend-down were introduced in paper N4232 2 and carried forward
            in P0158 9 to distinguish stackless ( suspend-up ) and stackful (
            suspend-down ) context switching. These terms rely on a particular
            visualization of the C++ function call operation in which calling a
            function passes control “downwards,” whereas returning from a function
            passes control “upwards.” The authors recommend the terms
            suspend-by-return instead of suspend-up , and suspend-by-call instead
            of
            suspend-down . The recommended terminology directly references the
            underlying C++ operations, without requiring a particular
            visualization.
            suspend-by-return ( suspend-up , or “stackless” context
            switching) is based on returning control from a called function to its
            caller, along with some indication as to whether the called function
            has completed and is returning a result or is merely suspending and
            expects to be called again. The called function’s body is coded in
            such a way that – if it suspended – calling it again will direct
            control to the point from which it last returned. This describes both
            P0057 6 resumable functions and earlier technologies such as
            Boost.Asio coroutines. 12
            suspend-by-call ( suspend-down, or
            “stackful” context switching) is based on calling a function which,
            transpar- ently to its caller, switches to some other logical chain of
            function activation records. (This may or may not be a contiguous
            stack area. The processor’s stack pointer register, if any, may or may
            not be involved.) This describes N4397 3 coroutines as well as
            Boost.Context, 13 Boost.Coroutine2 14 and Boost.Fiber. 15
            std::execution_context<>::operator()() requires suspend-by-call
            semantics.




            Both are old papers and is separate from p0057 which seems to be the main coroutines paper. p0444 discusses trying to unify these paper but does not seem to have gone anywhere. Also see Trip Report: C++ Standards Meeting in Issaquah, November 2016 which says:




            The Coroutines TS contains the co_await proposal, based on Microsoft’s original design.



            As mentioned previously, there are efforts underway to standardize a proposal for a different, stackful flavour of coroutines, as well as an exploratory effort to unify the two flavours under a common syntax. These proposals, however, are not currently slated to target the Coroutines TS. They may instead target a different TS (and if a unified syntax emerges, it could be that syntax, rather than the one in the Coroutines TS, that’s ultimately merged into the C++ standard).







            share|improve this answer

























            • Also relevant stackoverflow.com/questions/28977302/…

              – sdgfsdh
              Nov 14 '18 at 9:33















            3














            The terminology seems to be explained in p0099r1: "A low-level API for stackful context switching" which says:




            Notes on suspend-up and suspend-down terminology The terms suspend-up
            and suspend-down were introduced in paper N4232 2 and carried forward
            in P0158 9 to distinguish stackless ( suspend-up ) and stackful (
            suspend-down ) context switching. These terms rely on a particular
            visualization of the C++ function call operation in which calling a
            function passes control “downwards,” whereas returning from a function
            passes control “upwards.” The authors recommend the terms
            suspend-by-return instead of suspend-up , and suspend-by-call instead
            of
            suspend-down . The recommended terminology directly references the
            underlying C++ operations, without requiring a particular
            visualization.
            suspend-by-return ( suspend-up , or “stackless” context
            switching) is based on returning control from a called function to its
            caller, along with some indication as to whether the called function
            has completed and is returning a result or is merely suspending and
            expects to be called again. The called function’s body is coded in
            such a way that – if it suspended – calling it again will direct
            control to the point from which it last returned. This describes both
            P0057 6 resumable functions and earlier technologies such as
            Boost.Asio coroutines. 12
            suspend-by-call ( suspend-down, or
            “stackful” context switching) is based on calling a function which,
            transpar- ently to its caller, switches to some other logical chain of
            function activation records. (This may or may not be a contiguous
            stack area. The processor’s stack pointer register, if any, may or may
            not be involved.) This describes N4397 3 coroutines as well as
            Boost.Context, 13 Boost.Coroutine2 14 and Boost.Fiber. 15
            std::execution_context<>::operator()() requires suspend-by-call
            semantics.




            Both are old papers and is separate from p0057 which seems to be the main coroutines paper. p0444 discusses trying to unify these paper but does not seem to have gone anywhere. Also see Trip Report: C++ Standards Meeting in Issaquah, November 2016 which says:




            The Coroutines TS contains the co_await proposal, based on Microsoft’s original design.



            As mentioned previously, there are efforts underway to standardize a proposal for a different, stackful flavour of coroutines, as well as an exploratory effort to unify the two flavours under a common syntax. These proposals, however, are not currently slated to target the Coroutines TS. They may instead target a different TS (and if a unified syntax emerges, it could be that syntax, rather than the one in the Coroutines TS, that’s ultimately merged into the C++ standard).







            share|improve this answer

























            • Also relevant stackoverflow.com/questions/28977302/…

              – sdgfsdh
              Nov 14 '18 at 9:33













            3












            3








            3







            The terminology seems to be explained in p0099r1: "A low-level API for stackful context switching" which says:




            Notes on suspend-up and suspend-down terminology The terms suspend-up
            and suspend-down were introduced in paper N4232 2 and carried forward
            in P0158 9 to distinguish stackless ( suspend-up ) and stackful (
            suspend-down ) context switching. These terms rely on a particular
            visualization of the C++ function call operation in which calling a
            function passes control “downwards,” whereas returning from a function
            passes control “upwards.” The authors recommend the terms
            suspend-by-return instead of suspend-up , and suspend-by-call instead
            of
            suspend-down . The recommended terminology directly references the
            underlying C++ operations, without requiring a particular
            visualization.
            suspend-by-return ( suspend-up , or “stackless” context
            switching) is based on returning control from a called function to its
            caller, along with some indication as to whether the called function
            has completed and is returning a result or is merely suspending and
            expects to be called again. The called function’s body is coded in
            such a way that – if it suspended – calling it again will direct
            control to the point from which it last returned. This describes both
            P0057 6 resumable functions and earlier technologies such as
            Boost.Asio coroutines. 12
            suspend-by-call ( suspend-down, or
            “stackful” context switching) is based on calling a function which,
            transpar- ently to its caller, switches to some other logical chain of
            function activation records. (This may or may not be a contiguous
            stack area. The processor’s stack pointer register, if any, may or may
            not be involved.) This describes N4397 3 coroutines as well as
            Boost.Context, 13 Boost.Coroutine2 14 and Boost.Fiber. 15
            std::execution_context<>::operator()() requires suspend-by-call
            semantics.




            Both are old papers and is separate from p0057 which seems to be the main coroutines paper. p0444 discusses trying to unify these paper but does not seem to have gone anywhere. Also see Trip Report: C++ Standards Meeting in Issaquah, November 2016 which says:




            The Coroutines TS contains the co_await proposal, based on Microsoft’s original design.



            As mentioned previously, there are efforts underway to standardize a proposal for a different, stackful flavour of coroutines, as well as an exploratory effort to unify the two flavours under a common syntax. These proposals, however, are not currently slated to target the Coroutines TS. They may instead target a different TS (and if a unified syntax emerges, it could be that syntax, rather than the one in the Coroutines TS, that’s ultimately merged into the C++ standard).







            share|improve this answer















            The terminology seems to be explained in p0099r1: "A low-level API for stackful context switching" which says:




            Notes on suspend-up and suspend-down terminology The terms suspend-up
            and suspend-down were introduced in paper N4232 2 and carried forward
            in P0158 9 to distinguish stackless ( suspend-up ) and stackful (
            suspend-down ) context switching. These terms rely on a particular
            visualization of the C++ function call operation in which calling a
            function passes control “downwards,” whereas returning from a function
            passes control “upwards.” The authors recommend the terms
            suspend-by-return instead of suspend-up , and suspend-by-call instead
            of
            suspend-down . The recommended terminology directly references the
            underlying C++ operations, without requiring a particular
            visualization.
            suspend-by-return ( suspend-up , or “stackless” context
            switching) is based on returning control from a called function to its
            caller, along with some indication as to whether the called function
            has completed and is returning a result or is merely suspending and
            expects to be called again. The called function’s body is coded in
            such a way that – if it suspended – calling it again will direct
            control to the point from which it last returned. This describes both
            P0057 6 resumable functions and earlier technologies such as
            Boost.Asio coroutines. 12
            suspend-by-call ( suspend-down, or
            “stackful” context switching) is based on calling a function which,
            transpar- ently to its caller, switches to some other logical chain of
            function activation records. (This may or may not be a contiguous
            stack area. The processor’s stack pointer register, if any, may or may
            not be involved.) This describes N4397 3 coroutines as well as
            Boost.Context, 13 Boost.Coroutine2 14 and Boost.Fiber. 15
            std::execution_context<>::operator()() requires suspend-by-call
            semantics.




            Both are old papers and is separate from p0057 which seems to be the main coroutines paper. p0444 discusses trying to unify these paper but does not seem to have gone anywhere. Also see Trip Report: C++ Standards Meeting in Issaquah, November 2016 which says:




            The Coroutines TS contains the co_await proposal, based on Microsoft’s original design.



            As mentioned previously, there are efforts underway to standardize a proposal for a different, stackful flavour of coroutines, as well as an exploratory effort to unify the two flavours under a common syntax. These proposals, however, are not currently slated to target the Coroutines TS. They may instead target a different TS (and if a unified syntax emerges, it could be that syntax, rather than the one in the Coroutines TS, that’s ultimately merged into the C++ standard).








            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 14 '18 at 2:23

























            answered Nov 14 '18 at 1:50









            Shafik YaghmourShafik Yaghmour

            126k23324537




            126k23324537












            • Also relevant stackoverflow.com/questions/28977302/…

              – sdgfsdh
              Nov 14 '18 at 9:33

















            • Also relevant stackoverflow.com/questions/28977302/…

              – sdgfsdh
              Nov 14 '18 at 9:33
















            Also relevant stackoverflow.com/questions/28977302/…

            – sdgfsdh
            Nov 14 '18 at 9:33





            Also relevant stackoverflow.com/questions/28977302/…

            – sdgfsdh
            Nov 14 '18 at 9:33













            0














            each function creates a stack frame (reserves space on the stack for local variables etc.)



            suspend-up:



            • used by stackless context switching (coroutines...)

            • because you have only one stack (applications stack), you have to remove the stack frame of the suspended function (function of stackless coroutine)

            • otherwise other functions, executed after the coroutine has been suspended, would write their own stack frame and thus corrupt the stack frame of the suspended one

            • suspend-up == remove stack frame of suspended function == step some addresses at the stack upwards (for architectures where the stack grows from high to low addresses)

            suspend-down:



            • used by stackful context switching (coroutines, fibers, ...)

            • each coroutine/fiber gets their own stack, thus the application consist out of multiple stacks

            • if a stackful coroutine is suspended, the stack frame remains on the stack (because zhr stack is specific to/owned by the coroutine)

            • the stack pointer is simply changed to another stack (== switching to another stackful coroutine/fiber)

            • because the stack frame remains on the stack, it is called suspend-down





            share|improve this answer



























              0














              each function creates a stack frame (reserves space on the stack for local variables etc.)



              suspend-up:



              • used by stackless context switching (coroutines...)

              • because you have only one stack (applications stack), you have to remove the stack frame of the suspended function (function of stackless coroutine)

              • otherwise other functions, executed after the coroutine has been suspended, would write their own stack frame and thus corrupt the stack frame of the suspended one

              • suspend-up == remove stack frame of suspended function == step some addresses at the stack upwards (for architectures where the stack grows from high to low addresses)

              suspend-down:



              • used by stackful context switching (coroutines, fibers, ...)

              • each coroutine/fiber gets their own stack, thus the application consist out of multiple stacks

              • if a stackful coroutine is suspended, the stack frame remains on the stack (because zhr stack is specific to/owned by the coroutine)

              • the stack pointer is simply changed to another stack (== switching to another stackful coroutine/fiber)

              • because the stack frame remains on the stack, it is called suspend-down





              share|improve this answer

























                0












                0








                0







                each function creates a stack frame (reserves space on the stack for local variables etc.)



                suspend-up:



                • used by stackless context switching (coroutines...)

                • because you have only one stack (applications stack), you have to remove the stack frame of the suspended function (function of stackless coroutine)

                • otherwise other functions, executed after the coroutine has been suspended, would write their own stack frame and thus corrupt the stack frame of the suspended one

                • suspend-up == remove stack frame of suspended function == step some addresses at the stack upwards (for architectures where the stack grows from high to low addresses)

                suspend-down:



                • used by stackful context switching (coroutines, fibers, ...)

                • each coroutine/fiber gets their own stack, thus the application consist out of multiple stacks

                • if a stackful coroutine is suspended, the stack frame remains on the stack (because zhr stack is specific to/owned by the coroutine)

                • the stack pointer is simply changed to another stack (== switching to another stackful coroutine/fiber)

                • because the stack frame remains on the stack, it is called suspend-down





                share|improve this answer













                each function creates a stack frame (reserves space on the stack for local variables etc.)



                suspend-up:



                • used by stackless context switching (coroutines...)

                • because you have only one stack (applications stack), you have to remove the stack frame of the suspended function (function of stackless coroutine)

                • otherwise other functions, executed after the coroutine has been suspended, would write their own stack frame and thus corrupt the stack frame of the suspended one

                • suspend-up == remove stack frame of suspended function == step some addresses at the stack upwards (for architectures where the stack grows from high to low addresses)

                suspend-down:



                • used by stackful context switching (coroutines, fibers, ...)

                • each coroutine/fiber gets their own stack, thus the application consist out of multiple stacks

                • if a stackful coroutine is suspended, the stack frame remains on the stack (because zhr stack is specific to/owned by the coroutine)

                • the stack pointer is simply changed to another stack (== switching to another stackful coroutine/fiber)

                • because the stack frame remains on the stack, it is called suspend-down






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 26 '18 at 8:39









                xlrgxlrg

                1,00589




                1,00589



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291812%2fwhat-is-the-difference-between-suspend-up-and-suspend-down-coroutines%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    How to read a connectionString WITH PROVIDER in .NET Core?

                    In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

                    Museum of Modern and Contemporary Art of Trento and Rovereto