Reputation: 866
I've been exploring C++'s concurrency features, specifically around futures and promises. I came across two different ways to obtain a std::shared_future, and I'm trying to understand if there's any significant difference between them.
Method 1: Directly from std::promise
std::promise<int> prms;
std::shared_future<int> fut = prms.get_future();
Method 2: Converting a std::future
to std::shared_future
std::promise<int> prms;
std::future<int> fut = prms.get_future();
std::shared_future<int> sfut = fut.share();
Functionally, do these two methods result in any difference in behavior, performance, or other aspects? Is one method preferred over the other in certain scenarios?
Upvotes: 0
Views: 99