the following program give some strange compile/run-time behavior when compiled with Visual Studio 2013:
#include "stdafx.h"
#include <thread>
#include <chrono>
#include <iostream>
int main()
{
{//works
std::thread([](){
std::cout << " thread running1\n";
});
}
{//compile but synstax error exist
auto func = [](){
std::cout << " thread running2\n";
};
std::thread(fun); //fun is not defined
}
{//compile, see next block for mystery compile error
auto func = [](){
std::cout << " thread running2\n";
};
std::thread tmp(func);
}
{//does not compile and don't know why
auto func = [](){
std::cout << " thread running2\n";
};
std::thread(func); //error C2371: 'func' : redefinition; different basic types
}
return 0;
}
When this program work, there may crash as there is race condition between the thread. The main thread may end before the other threads.
Does anybody know why the second block and last block does not work?
Aucun commentaire:
Enregistrer un commentaire