0

Tried to run some sample code.
But something unexpected occured.
I wonder is there any known issus about boost.thread used with libc++ together ?


Program compiled with -std=c++11 or no option runs well.

But when I compiled with -stdlib=libc++ or -std=c++11 -stdlib=libc++
The output was like:

in main
in thread
bash: line 1: 37501 Segmentation fault: 11  ./a.out

Compiler:
Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.3.0
Thread model: posix

OS: Mac OS X 10.8.3

The sample code is quite simple:

#include "stdio.h"
#include <boost/thread/thread.hpp>

class callable
{
public:
    void operator()()
    {
        printf("in thread\n");
    }
};

int main()
{
    boost::thread t = boost::thread(callable());
    printf("in main\n");
    t.join();
    return 0;
}
silvesthu
  • 399
  • 3
  • 12
  • IIRC, I already seen this issue somewhere(because I have a similar problem), but I can't remember where... :( – awesoon May 05 '13 at 13:20
  • @BЈовић I only used `c++` in terminal. – silvesthu May 05 '13 at 14:25
  • 4
    You will need to make sure boost is configured with the c++11 flags as well. As an aside, unless you are looking for interruption points or some similar thing why not use std::thread ? – dirvine May 05 '13 at 17:26
  • 1
    @dirvine You are right.I compiled boost again with c++11.It runs well. So it's just my mistake on using boost. Thank you. – silvesthu May 06 '13 at 06:15

1 Answers1

0

boost.thread is probably linked to libstdc++. libstdc++ and libc++ have incompatible ABI. They shouldn't be used both in one program.

Hristo Venev
  • 972
  • 5
  • 17