tags:

views:

370

answers:

1

although it's been said that the support for c++0x new features in g++ are in experimental mode, many gcc developer claimed that you can use most of the new features in your codes and get the program to work.

but when I try to compile this simple program it results in segmentation fault. Why?

#include <thread>
#include <iostream>

void my_thread_func()
{
    std::cout<<"hello"<<std::endl;
}

int main()
{
    std::thread t(my_thread_func);
    t.join();
}

g++ -std=c++0x -Wall -o run main.cc

+4  A: 

I linked the executable with pthread library and it worked! I did not see any missing shared library dependency (ldd), but seems like std C++ library implementation on Linux uses pthread internally.

g++ thread.cpp -o thread -Wall -std=c++0x -lpthread
Sumant
Oh my god, How much silly i am. Thanks Sumant, It works well with -lpthread switch
SepiDev
I thought that there would be a separate implementation of c++0x thread in g++, but as you said it currently uses posix thread library.
SepiDev