Consider I have lamba foo which just does some stuff and doesn’t need to return anything.
When I do this:
std::future<T> handle = std::async(std::launch::async, foo, arg1, arg2);
Everything runs fine and the lamba will be spawned in a new thread.
However, when I don’t store the std::future which the std::async returns, the foo will be run in the main thread and block it.
std::async(std::launch::async, foo, arg1, arg2);
What am I missing here?
From
just::threaddocumentation:In
The returned future is not assigned anywhere and its destructor blocks until
foofinishes.