Is it legal to call shared_future::get() multiple times on the same instance in the same thread?Purpose of Unions in C and C++Accessing inactive union member and undefined behavior?boost::thread and starting or not starting large numbers of threads at the same timeWhy is f(i = -1, i = -1) undefined behavior?Call a function from another threadboost::thread and std::thread compatibility issues?How to implement classic sorting algorithms in modern C++?Is the Visual C++ implementation of std::async using a thread pool legalIs it legal to call delete on a null pointer of an incomplete type?May a call to std::lock pass a resource that is already locked by the calling thread?

Milky way is orbiting around?

What is the maximum amount of diamond in one Minecraft game?

Are "confidant" and "confident" homophones?

Advice for making/keeping shredded chicken moist?

What is the fundamental difference between catching whales and hunting other animals?

Did Stalin kill all Soviet officers involved in the Winter War?

In the Seventh Seal why does Death let the chess game happen?

What units are kpts?

How can one synthesise a conjugated alkyne chain?

What is exact meaning of “ich wäre gern”?

Does a multiclassed wizard start with a spellbook?

Chess problem: Make a crossword in 3 moves

Bypass with wrong cvv of debit card and getting OTP

How to improve the size of cells in this table?

How did שְׁלֹמֹה (shlomo) become Solomon?

Platform Event Design when Subscribers are Apex Triggers

What do you call the angle of the direction of an airplane?

Park the computer

Is it possible to spoof an IP address to an exact number?

Contributing to a candidate as a Foreign National US Resident?

Why did C++11 make std::string::data() add a null terminating character?

Why did the "Orks" never develop better firearms than Firelances and Handcannons?

Minimizing medical costs with HSA

PhD: When to quit and move on?



Is it legal to call shared_future::get() multiple times on the same instance in the same thread?


Purpose of Unions in C and C++Accessing inactive union member and undefined behavior?boost::thread and starting or not starting large numbers of threads at the same timeWhy is f(i = -1, i = -1) undefined behavior?Call a function from another threadboost::thread and std::thread compatibility issues?How to implement classic sorting algorithms in modern C++?Is the Visual C++ implementation of std::async using a thread pool legalIs it legal to call delete on a null pointer of an incomplete type?May a call to std::lock pass a resource that is already locked by the calling thread?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








8















I can find neither direct confirmation nor refutation on the matter. All answers seem to address the "access from multiple threads" aspect, rather than repetitive access itself.



Does the standard define the behavior for std::shared_future? What about boost::shared_future?










share|improve this question




























    8















    I can find neither direct confirmation nor refutation on the matter. All answers seem to address the "access from multiple threads" aspect, rather than repetitive access itself.



    Does the standard define the behavior for std::shared_future? What about boost::shared_future?










    share|improve this question
























      8












      8








      8


      2






      I can find neither direct confirmation nor refutation on the matter. All answers seem to address the "access from multiple threads" aspect, rather than repetitive access itself.



      Does the standard define the behavior for std::shared_future? What about boost::shared_future?










      share|improve this question














      I can find neither direct confirmation nor refutation on the matter. All answers seem to address the "access from multiple threads" aspect, rather than repetitive access itself.



      Does the standard define the behavior for std::shared_future? What about boost::shared_future?







      c++ boost future






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jun 25 at 14:15









      vinesvines

      4,4681 gold badge20 silver badges44 bronze badges




      4,4681 gold badge20 silver badges44 bronze badges






















          2 Answers
          2






          active

          oldest

          votes


















          12














          Per cppreference in std::shared_future<T>::valid




          Unlike std::future, std::shared_future's shared state is not invalidated when get() is called.




          Which makes sense. If it wasn't the case then you couldn't have multiple threads be able to call get. We can further back this up by looking at the standard. In [futures.unique.future]/15 they explicitly state get only works once with




          releases any shared state ([futures.state]).




          while in [futures.shared.future]/18 it states no such thing so the state is still valid after get is called.




          boost::shared_future has the same behavior. Per the reference get has no text stating it invalidates the shared state on a call to get so you can call it multiple times.






          share|improve this answer

























          • By the way, a curious observation on boost::futures. The link in the answer leads to docs on boost::fibers::shared_future, which (again!) seem to differ in behavior from boost::shared_future (which is defined in 'boost::thread').

            – vines
            Jun 25 at 15:11












          • @vines Oh wow. Didn't notice that. I'll fix the answer.

            – NathanOliver
            Jun 25 at 15:15











          • Ah, found! It is stated in the first example on shared_future: use3( ftr.get() ); // second use is defined

            – vines
            Jun 25 at 16:23


















          8














          AFAIK this is legal. std::shared_future<T>::get() says:




          The behavior is undefined if valid() is false before the call to this
          function.




          Going to std::shared_future<T>::valid() it says:




          Checks if the future refers to a shared state.



          ...



          Unlike std::future, std::shared_future's shared state is not
          invalidated when get() is called
          .




          Which would make multiple get() calls from the same thread and on the same instance valid.






          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%2f56756112%2fis-it-legal-to-call-shared-futureget-multiple-times-on-the-same-instance-in%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









            12














            Per cppreference in std::shared_future<T>::valid




            Unlike std::future, std::shared_future's shared state is not invalidated when get() is called.




            Which makes sense. If it wasn't the case then you couldn't have multiple threads be able to call get. We can further back this up by looking at the standard. In [futures.unique.future]/15 they explicitly state get only works once with




            releases any shared state ([futures.state]).




            while in [futures.shared.future]/18 it states no such thing so the state is still valid after get is called.




            boost::shared_future has the same behavior. Per the reference get has no text stating it invalidates the shared state on a call to get so you can call it multiple times.






            share|improve this answer

























            • By the way, a curious observation on boost::futures. The link in the answer leads to docs on boost::fibers::shared_future, which (again!) seem to differ in behavior from boost::shared_future (which is defined in 'boost::thread').

              – vines
              Jun 25 at 15:11












            • @vines Oh wow. Didn't notice that. I'll fix the answer.

              – NathanOliver
              Jun 25 at 15:15











            • Ah, found! It is stated in the first example on shared_future: use3( ftr.get() ); // second use is defined

              – vines
              Jun 25 at 16:23















            12














            Per cppreference in std::shared_future<T>::valid




            Unlike std::future, std::shared_future's shared state is not invalidated when get() is called.




            Which makes sense. If it wasn't the case then you couldn't have multiple threads be able to call get. We can further back this up by looking at the standard. In [futures.unique.future]/15 they explicitly state get only works once with




            releases any shared state ([futures.state]).




            while in [futures.shared.future]/18 it states no such thing so the state is still valid after get is called.




            boost::shared_future has the same behavior. Per the reference get has no text stating it invalidates the shared state on a call to get so you can call it multiple times.






            share|improve this answer

























            • By the way, a curious observation on boost::futures. The link in the answer leads to docs on boost::fibers::shared_future, which (again!) seem to differ in behavior from boost::shared_future (which is defined in 'boost::thread').

              – vines
              Jun 25 at 15:11












            • @vines Oh wow. Didn't notice that. I'll fix the answer.

              – NathanOliver
              Jun 25 at 15:15











            • Ah, found! It is stated in the first example on shared_future: use3( ftr.get() ); // second use is defined

              – vines
              Jun 25 at 16:23













            12












            12








            12







            Per cppreference in std::shared_future<T>::valid




            Unlike std::future, std::shared_future's shared state is not invalidated when get() is called.




            Which makes sense. If it wasn't the case then you couldn't have multiple threads be able to call get. We can further back this up by looking at the standard. In [futures.unique.future]/15 they explicitly state get only works once with




            releases any shared state ([futures.state]).




            while in [futures.shared.future]/18 it states no such thing so the state is still valid after get is called.




            boost::shared_future has the same behavior. Per the reference get has no text stating it invalidates the shared state on a call to get so you can call it multiple times.






            share|improve this answer















            Per cppreference in std::shared_future<T>::valid




            Unlike std::future, std::shared_future's shared state is not invalidated when get() is called.




            Which makes sense. If it wasn't the case then you couldn't have multiple threads be able to call get. We can further back this up by looking at the standard. In [futures.unique.future]/15 they explicitly state get only works once with




            releases any shared state ([futures.state]).




            while in [futures.shared.future]/18 it states no such thing so the state is still valid after get is called.




            boost::shared_future has the same behavior. Per the reference get has no text stating it invalidates the shared state on a call to get so you can call it multiple times.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jun 25 at 15:16

























            answered Jun 25 at 14:22









            NathanOliverNathanOliver

            107k19 gold badges159 silver badges236 bronze badges




            107k19 gold badges159 silver badges236 bronze badges












            • By the way, a curious observation on boost::futures. The link in the answer leads to docs on boost::fibers::shared_future, which (again!) seem to differ in behavior from boost::shared_future (which is defined in 'boost::thread').

              – vines
              Jun 25 at 15:11












            • @vines Oh wow. Didn't notice that. I'll fix the answer.

              – NathanOliver
              Jun 25 at 15:15











            • Ah, found! It is stated in the first example on shared_future: use3( ftr.get() ); // second use is defined

              – vines
              Jun 25 at 16:23

















            • By the way, a curious observation on boost::futures. The link in the answer leads to docs on boost::fibers::shared_future, which (again!) seem to differ in behavior from boost::shared_future (which is defined in 'boost::thread').

              – vines
              Jun 25 at 15:11












            • @vines Oh wow. Didn't notice that. I'll fix the answer.

              – NathanOliver
              Jun 25 at 15:15











            • Ah, found! It is stated in the first example on shared_future: use3( ftr.get() ); // second use is defined

              – vines
              Jun 25 at 16:23
















            By the way, a curious observation on boost::futures. The link in the answer leads to docs on boost::fibers::shared_future, which (again!) seem to differ in behavior from boost::shared_future (which is defined in 'boost::thread').

            – vines
            Jun 25 at 15:11






            By the way, a curious observation on boost::futures. The link in the answer leads to docs on boost::fibers::shared_future, which (again!) seem to differ in behavior from boost::shared_future (which is defined in 'boost::thread').

            – vines
            Jun 25 at 15:11














            @vines Oh wow. Didn't notice that. I'll fix the answer.

            – NathanOliver
            Jun 25 at 15:15





            @vines Oh wow. Didn't notice that. I'll fix the answer.

            – NathanOliver
            Jun 25 at 15:15













            Ah, found! It is stated in the first example on shared_future: use3( ftr.get() ); // second use is defined

            – vines
            Jun 25 at 16:23





            Ah, found! It is stated in the first example on shared_future: use3( ftr.get() ); // second use is defined

            – vines
            Jun 25 at 16:23













            8














            AFAIK this is legal. std::shared_future<T>::get() says:




            The behavior is undefined if valid() is false before the call to this
            function.




            Going to std::shared_future<T>::valid() it says:




            Checks if the future refers to a shared state.



            ...



            Unlike std::future, std::shared_future's shared state is not
            invalidated when get() is called
            .




            Which would make multiple get() calls from the same thread and on the same instance valid.






            share|improve this answer





























              8














              AFAIK this is legal. std::shared_future<T>::get() says:




              The behavior is undefined if valid() is false before the call to this
              function.




              Going to std::shared_future<T>::valid() it says:




              Checks if the future refers to a shared state.



              ...



              Unlike std::future, std::shared_future's shared state is not
              invalidated when get() is called
              .




              Which would make multiple get() calls from the same thread and on the same instance valid.






              share|improve this answer



























                8












                8








                8







                AFAIK this is legal. std::shared_future<T>::get() says:




                The behavior is undefined if valid() is false before the call to this
                function.




                Going to std::shared_future<T>::valid() it says:




                Checks if the future refers to a shared state.



                ...



                Unlike std::future, std::shared_future's shared state is not
                invalidated when get() is called
                .




                Which would make multiple get() calls from the same thread and on the same instance valid.






                share|improve this answer















                AFAIK this is legal. std::shared_future<T>::get() says:




                The behavior is undefined if valid() is false before the call to this
                function.




                Going to std::shared_future<T>::valid() it says:




                Checks if the future refers to a shared state.



                ...



                Unlike std::future, std::shared_future's shared state is not
                invalidated when get() is called
                .




                Which would make multiple get() calls from the same thread and on the same instance valid.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Jun 25 at 14:28

























                answered Jun 25 at 14:23









                Sombrero ChickenSombrero Chicken

                26.8k3 gold badges35 silver badges84 bronze badges




                26.8k3 gold badges35 silver badges84 bronze badges



























                    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%2f56756112%2fis-it-legal-to-call-shared-futureget-multiple-times-on-the-same-instance-in%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







                    Popular posts from this blog

                    Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

                    Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                    Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form