I am trying to establish some heuristics to help me decide the appropriate std::thread
class to use.
As I understand it, from highest level (simplest to
When you have two levels of async, you need to use a promise. Eg:
void fun()
{
std::promise p;
std::future f = p.get_future();
std::future f2;
auto f3 = std::async([&]{
// Do some other computation
f2 = std::async([&]{ p.set_value(42);});
// Do some other work
});
// Do some other work
// Now wait for the result of async work;
std::cout << f.get();
// Do some other work again
// Wait for async threads to complete
f3.wait();
f2.wait();
}