I am reading about behaviour of thread handle destructor in C++ 11 by Scott Meyers book.
Here author is discussing about result can be stored in future or in promise in callee and explaining why result can't be stored in the caller's future as below.
The result can't be stored in the caller's future, either because (among other reasons) a std::future may be used to create a std::shared_future (thus transferring ownership of the callee's result from the std::fture to the std::shared future), which may then be copied many times after the orignal std::future is destroyed. Given that not all result types can be copied (i.e., move-only types) and that the result must live atleast as long as the last future referring to it, which of the potentially many futures corresponding to the callee should be the one to contain its result.
Because neither objects associated with the callee nor objects associated with the caller are suitable places to store callee's result, it is stored in a location outside both. This location is known as the shared state. The shared state is typically represented by a heap based object, but its type, interface, and implementation are not specified by the standard. Standard library authors are free to implement shared states in any way they like.
Additoanl infomation at below link
My questions are
-
If you copy future we have complet copy why we bother about even if orginal future object is deleted or not?
-
What does author mean by "result must live atleast as long as the last future referring to it, which of the potentially many futures corresponding to the callee should be the one to contain its result" ?
Thanks for your time
Aucun commentaire:
Enregistrer un commentaire