我无法弄清楚我在这里做错了什么.这个非常短的计划:
#include <iostream>
#include <string>
#include <atomic>
#include <thread>
using namespace std;
int
main(int argc, char ** argv)
{
thread foo( []() {
cout << "Hello World" << endl;
return 0;
} );
foo.join();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译时它完美地工作gcc (4.7.2):
$ g++ -ggdb -std=c++11 -pthread -o clang_thread_test clang_thread_test.cpp
$ ./clang_thread_test
Hello World
Run Code Online (Sandbox Code Playgroud)
但是,使用clang (3.2; x86_64-pc-linux-gnu; thread model: posix)它编译时无法执行:
$ clang++ -ggdb -std=c++11 -pthread -o clang_thread_test clang_thread_test.cpp
$ ./clang_thread_test
pure virtual method called
terminate called without an active …Run Code Online (Sandbox Code Playgroud)