小编A. *_*cht的帖子

在使用dlopen加载的库中使用std :: thread会导致sigsev

我最近发现了一个使用std::thread和的奇怪行为dlopen.

基本上,当我std::thread在一个使用dlopen我收到sigsev 的库中执行a时.库本身与pthread链接,pthread是调用的可执行文件dlopen.

一旦我链接可执行文件pthread或库本身一切正常.但是,我们使用的是基于插件的基础架构,我们不知道应用程序本身是否与pthread相关联.因此,不能将可执行文件始终链接到pthread.

请附上一些代码来重现问题.目前我不确定导致该问题的原因.这是gcc,glibc,libstdc ++还是ld.so的问题?有没有一种方便的方法来解决这个问题?我看起来这个glibc bug是相关的,但我使用的是glibc2.27(debian测试).

pthread_create从图书馆打电话似乎很有效.

HELLO.CPP

#include <thread>
#include <iostream>

void thread()
{
    std::thread t ([](){std::cout << "hello world" << std::endl;});
    t.join();
}

extern "C" {
    void hello()
    {
        thread();
    }
}
Run Code Online (Sandbox Code Playgroud)

example.cpp

#include <iostream>
#include <dlfcn.h>

/** code from https://www.tldp.org/HOWTO/html_single/C++-dlopen/
*/
int main() {

    std::cout << "C++ dlopen demo\n\n";

    // open the library
    std::cout << "Opening hello.so...\n";
    void* handle = dlopen("./libhello.so", …
Run Code Online (Sandbox Code Playgroud)

c++ glibc dlopen stdthread

8
推荐指数
2
解决办法
492
查看次数

标签 统计

c++ ×1

dlopen ×1

glibc ×1

stdthread ×1