The std::launch::async launch policy means that f must be run asynchronously,i.e., on a different thread.
The std::launch::deferred launch policy means that f may run only when get or wait is called on the future returned by std::async. That is, f’s execution is deferred until such a call is made. When get or wait is invoked, f will execute synchronously, the caller will block until f finishes running. If neither get nor wait called, f will never run.
if f is deferred fut.wait_for() == future_status::deferred
std::async’s default launch policy
auto fut1 = std::async(f); // run f using default launch policy
auto fut2 = std::async(std::launch::async | std::launch::deferred, f);
template<typename F, typename... Ts>
inline
std::future<typename std::result_of<F(Ts...)>::type>
reallyAsync(F&& f, Ts&&... params) {
return std::async(std::launch::async, std::forward<F>(f), std::forward<Ts>(params)...);
}
tempate<typename F, typename... Ts>
inline
auto
reallyAsync(F&& f, Ts&&... params) {
return std::async(std::lauch::async, std::forward<F>(f), std::forward<Ts>(params)...);
}