c++boostboost-threadpantheios

Pantheios and boost::thread


I am having some trouble using the pantheios logging library with boost::threads. It seems that if I use any pantheios logging before creating the thread, I will get a segfault.

For example, the following would work:

thread_ = new boost::thread(&foo);
pantheios::log(pantheios::debug, "Hello world");

But if the order of the statements are switched, a stack trace reveals that I crash on start_thread in boost.

pantheios::log(pantheios::debug, "Hello world");
thread_ = new boost::thread(&foo);
// SEGFAULT!

Any ideas?

EDIT: More context

int main()
{
    pantheios::log(...);
    MyClass myClass(/* some arguments, which are all literals */);

    // Do some more work

    return 0;
}

// MyClass constructor
MyClass::MyClass(/* args */)
    : member1_(arg1)
    , member2_(arg2)
{
    thread_ = new boost::thread(&MyClass::workerLoop, this);
}

// Destructor
MyClass::~MyClass()
{
    thread_->join();
    delete thread_;
}

This will segfault at start_thread. Once again if I swap the two lines in main it will work without any problems.


Solution

  • Looks like I figured it out. I was linking to different versions of boost. My system had boost version 1.40, whereas I was also using a newer version of boost I downloaded, 1.49. Notable the boost thread I was linking was to the older version.

    Once I made the links to boost consistent, everything worked as expected.