Pantheios and boost::thread

Pantheios and boost::thread

本文关键字:thread boost and Pantheios      更新时间:2023-10-16

我在使用带有 boost::threads 的 pantheios 日志记录库时遇到了一些问题。似乎如果我在创建线程之前使用任何 pantheios 日志记录,我会得到一个段错误。

例如,以下方法有效:

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

但是,如果语句的顺序被切换,堆栈跟踪显示我在 boost 中崩溃start_thread

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

有什么想法吗?

编辑:更多背景

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_;
}

这将在start_thread处出现段错误。再一次,如果我交换main的两行,它将毫无问题地工作。

看来我想通了。我链接到不同版本的boost.我的系统有 boost 版本 1.40,而我也在使用我下载的较新版本的 boost 1.49。值得注意的是,我链接的提升线程是旧版本的。

一旦我建立了链接以保持一致性,一切都按预期工作。