This sample prints all 2 messages under windows7 and on ideone.com, but fails to print second message on windows xp. What im doing wrong? If it is a bug, where i should report it?
Compiled for windows xp using visual studio 2017, platform toolset v141_xp.
#include <iostream>
#include <future>
#include <thread>
using namespace std;
int main()
{
auto f1 = async(launch::async, []()->int {
cout << "in outer async" << endl;
auto f2 = async(launch::async, []()->int {
cout << "in inner async" << endl;
return 2;
});
f2.get();
return 1;
});
f1.get();
return 0;
}
UPD when using std::thread instead of std::async for inner function - it works well on both systems
auto f2 = thread([]()->int {
cout << "in inner async" << endl;
return 2;
});
f2.join();
UPD2
visual studio 2017 cl.exe version 19.14.26428 toolset v141_xp
commandline:
/permissive- /Yu"stdafx.h" /GS /GL /analyze- /Wall /Gy /Zc:wchar_t /Zi /Gm- /O2 /sdl /Fd"Release\vc141.pdb" /Zc:inline /fp:precise /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_USING_V110_SDK71_" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /Gd /Oy- /Oi /MD /std:c++17 /FC /Fa"Release\" /EHsc /nologo /Fo"Release\" /Fp"Release\testasync.pch" /diagnostics:classic
UPD3 looks like launch::async is ignored when used on windows xp
vector<future<void>> v;
for( int i = 0; i < 10; i++ )
v.push_back(async(launch::async, []() {cout << "thread" << endl; this_thread::sleep_for(5s); }));
for( auto &f : v )
f.get();
on windows7 this tooks ~6seconds to complete, on windows xp ~50 seconds