I can't figure out what I'm doing wrong here. This very short program:
#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;
}
It works perfectly when compiled with gcc (4.7.2)
:
$ g++ -ggdb -std=c++11 -pthread -o clang_thread_test clang_thread_test.cpp
$ ./clang_thread_test
Hello World
However, when compiled with clang (3.2; x86_64-pc-linux-gnu; thread model: posix)
it fails to execute:
$ 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 exception
Aborted
Is there a known reason for this? The only things I found were related to a missing -pthread switch
or a not used libc++
. To my knowledge the latter is only relevant on apple-systems.