This setup
void run()
{
while (true)
{
std::cout << "Hello, Thread!\n";
std::this_thread::sleep_for(std::chrono::seconds(1));
}
}
void foo()
{
std::thread t(run);
t.detach();
//std::this_thread::sleep_for(std::chrono::seconds(3));
}
int main()
{
foo();
getchar();
}
Gives me no output until I press enter (getchar returns and program ends, but I can see the output for a short while). However, when use the out commented line from foo, the output is shown directly. (Even after foo returns.) I'm using the VS11 beta version. Which behavior is required here according to the standard?