[Help-gnutls] thread safety of gnutls
Ang Way Chuang
wcang at yahoo.com
Fri Mar 3 09:14:54 CET 2006
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/attachments/20060303/92a51164/attachment.htm>
More information about the Gnutls-help
mailing list