我正在使用VS2013。
我刚刚读了this,发现未来应该在其析构函数中封锁。
为什么std :: future不会阻止
我试了一些代码,但std::future
没有阻止。
void PrintFoo()
{
while (true)
{
std::cout << "Foo" << std::endl;
Sleep(1000);
}
}
int _tmain(int argc, _TCHAR* argv[])
{
{
auto f = std::async(std::launch::async, PrintFoo);
}
while (true)
{
Sleep(1000);
std::cout << "Waiting" << std::endl;
}
std::cout << "Before application end" << std::endl;
return 0;
}
我有输出:
Foo
Waiting
Foo
Waiting
我误解的东西吗?
VS2017不会重现此行为。正如预期的那样,它只是不断打印'Foo'。 – AnT