In fact, you serialize calls waiting for each one, since the same thread can be reused without violating the specification executed by the std::futurethread other than the callerβs thread
, Caller ThreadId:
void PrintThreadId()
{
std::cout << std::this_thread::get_id() << std::endl;
}
int main()
{
std::cout << "Caller threadId (to be different from any id of the future exec thread): ";
PrintThreadId();
for (int i = 0; i < 5; ++i)
{
auto f = std::async(std::launch::async, PrintThreadId);
f.wait();
}
}