On the other hand with launch::deferred foo() will be executed on the same thread, and at the moment when future.wait() or future.get() would be called.
void foo () {
std::cout << "foo threadid = " << std::this_thread::get_id() << '\n';
}
int main()
{
std::cout << "my threadid = " << std::this_thread::get_id() << '\n';
std::future fut = std::async(std::launch::deferred, foo);
fut.get();
return 0;
}
my threadid = 140737353906048 foo threadid = 140737353906048
No comments :
Post a Comment