_gcry_ath_mutex_lock: Assertion `*lock == ((ath_mutex_t) 0)' failed.

如果你的多线程程序出现如题的错误,然后直接 Aborted (core dumped) 掉,那么一定是由于你所使用的gnutls接口没有进行锁的初始化,

在程序初始化时加入以下代码即可:

#include <gnutls/gnutls.h>

static int mutex_init(void **mutex)
{
    *mutex = malloc(sizeof(pthread_mutex_t));
    pthread_mutex_init(*mutex, NULL);
    return 0;
}

static int mutex_lock(void **mutex)
{
    pthread_mutex_lock(*mutex);
    return 0;
}

static int mutex_unlock(void **mutex)
{
    pthread_mutex_unlock(*mutex);
    return 0;
}

static int mutex_deinit(void **mutex)
{
    pthread_mutex_destroy(*mutex);
    free(*mutex);
    return 0;
}

int main(int argc, char **argv)
{
    gnutls_global_set_mutex(mutex_init, mutex_deinit,
                            mutex_lock, mutex_unlock);
    gnutls_global_init();

    // your codes

    return 0;
}


你可能感兴趣的:(多线程,null)