help-gnutls
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-gnutls] thread safety of gnutls


From: Ang Way Chuang
Subject: [Help-gnutls] thread safety of gnutls
Date: Fri, 3 Mar 2006 08:14:54 +0000 (GMT)

Hi all,
   I am very sorry for asking too many questions. I ran a multithread test on gnutls_record_{recv,send}. When there are multiple threads using one of these functions
simultaneously, the application will segfault. However, if i protect these functions with mutex, it won't segfault. But i thought gnutls is thread safe by design.

I've called these in my app:

gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
gnutls_global_init();

Here is thread function:
void * tls_session(void * data) {  int ret;  char buf[501];  int times;  unsigned int len;  gnutls_session_t session = (gnutls_session_t) data;  
times = 30; len = times; memset(buf, 'a' + (rand() % ('z' - 'a')), len); buf[len] = 0; while (!term && !reload && times--) { //pthread_mutex_lock(&mutex); ret = gnutls_record_send(session, buf, len + 1); //pthread_mutex_unlock(&mutex); if (ret < 1) { fprintf(stderr, "Failed tls send %s\n", gnutls_strerror(ret)); break; } if (ret == 0) break; //pthread_mutex_lock(&mutex); ret = gnutls_record_recv(session, buf, sizeof(buf)); //pthread_mutex_unlock(&mutex); if (ret < 1) { fprintf(stderr, "Failed tls recv %s\n", gnutls_strerror(ret)); break; } if (ret == 0) break; } return NULL; }
If the pthread_mutex_{un,}lock is commented out. Are gnutls functions supposed to be protected using synchronization primitives? Thanks in advance.

Regards,
Ang Way Chuang



May you be well and happy


To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre.
reply via email to

[Prev in Thread] Current Thread [Next in Thread]