1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
// future::share
#include <iostream> // std::cout
#include <future> // std::async, std::future, std::shared_future
int get_value() { return 10; }
int main ()
{
std::future<int> fut = std::async (get_value);
std::shared_future<int> shfut = fut.share();
// shared futures can be accessed multiple times:
std::cout << "value: " << shfut.get() << '\n';
std::cout << "its double: " << shfut.get()*2 << '\n';
return 0;
}
|