Open main menu

CDOT Wiki β

Changes

GPU621/NoName

2 bytes removed, 00:59, 3 December 2016
Asynchronous Multi-Threading
• packaged_task::get_future
However, a future object can only be used if it is in a valid state. Default future objects constructed from the std::async template function are not valid and must be assigned a valid state during execution.
A std::future references a shared state that cannot be shared to other asynchronous return objects. If multiple threads need to wait for the same shared state, std::shared_future class template should be used.
Basic example of asynchronous multi-threading using std::async to create the thread and std::future to store the return result of their associated threads.
futures.push_back(std::async(twice, i));
}
for (int i = 0; i < futures.size(); i++){
std::cout << futures.at(i).get() << std::endl;
return 0;
}
 
 
===Programming Models===