Pointers 使用动态加载的pthread库调用pthread_join()的正确方法是什么

Pointers 使用动态加载的pthread库调用pthread_join()的正确方法是什么,pointers,segmentation-fault,pthreads,function-pointers,dynamic-loading,Pointers,Segmentation Fault,Pthreads,Function Pointers,Dynamic Loading,我犯了这个错误,我似乎无法摆脱它。将范围缩小到pthread_join函数。我正在动态加载libpthread int main(int argc, char **argv) { void *lib_handle; create pthread_c; join pthread_j; pthread_t thrd_id; int rc; char *error; lib_handle = dlopen("/lib/x86_64-linu

我犯了这个错误,我似乎无法摆脱它。将范围缩小到pthread_join函数。我正在动态加载libpthread

int main(int argc, char **argv) 
{
    void *lib_handle;
    create pthread_c;
    join pthread_j;
    pthread_t thrd_id;

    int rc;
    char *error;

    lib_handle = dlopen("/lib/x86_64-linux-gnu/libpthread.so.0", RTLD_NOW);

    if (!lib_handle) 
    {
        fprintf(stderr, "%s\n", dlerror());
        exit(1);
    }

    pthread_c = dlsym(lib_handle, "pthread_create");
    pthread_j = dlsym(lib_handle, "pthread_join");

    if ((error = dlerror()) != NULL)  
    {
        fprintf(stderr, "%s\n", error);
        exit(1);
    }

    rc = pthread_c(&thrd_id, NULL, sub, (void *)NULL);
    pthread_j(thrd_id, NULL);  // CAUSES SEGFAULT
    printf ("testing");

    dlclose(lib_handle);
    return 0;
}

void* sub (void* a)
{
    printf("Hello Thread, I'm the World!\n");
}

printf语句显示pthread_create正在正常工作。但是我需要调用pthread_join,否则程序会在线程旋转之前终止。

结果表明,您必须声明连接并创建typedefs,才能使用pthread_t而不是sys/types.h中的int

typedef int (*create)(pthread_t, void*, void*, void*);
typedef void (*join) (pthread_t, void*);
我想我在create中使用了int,但对join不起作用