Thread safety problem (?)

Vincent Deffontaines vincent.deffontaines at inl.fr
Mon Apr 18 17:51:03 CEST 2005


Greetings,

I use gcrypt in a multithreaded server app (namely, nufw [1]) (also uses 
glib and gnutls).

We experiment an occasionnal (hard to reproduce) crash which seems to 
always occur at the gnutls call : gnutls_handshake(). The crash is quite 
rare (and occurs in an often called loop), which leads us to believe 
this might be a thread safety problem.

Gnutls people pointed us (on this thread [2]) to the gcrypt, and told us 
we should use some locking mechanisms. Also, the "Multi-threaded 
applications" [3] webpage seems to be of interest.

Our server runs this :
static struct gcry_thread_cbs gcry_threads_gthread =
{
         GCRY_THREAD_OPTION_USER, NULL,
         gcry_gthread_mutex_init, gcry_gthread_mutex_destroy,
         gcry_gthread_mutex_lock, gcry_gthread_mutex_unlock
};

and this :

g_thread_init(NULL);
gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_gthread);
gnutls_global_init();

which doesn't seem to be enough to solve our problem.

As usual, the thread safety problems are very delicate, and we of course 
cannot be sure this is gcrypt's "fault" or ours, or whatever.

If anyone on this list has more ideas about what to check/add, we will 
be very interested to hear about it.

Any help/pointer will be appreciated.

Thanks for reading me,

Vincent Deffontaines



[1] http://www.nufw.org/
[2] http://lists.gnu.org/archive/html/help-gnutls/2005-04/msg00009.html
[3] 
http://www.gnu.org/software/gnutls/manual/html_node/Multi_002dthreaded-applications.html#Multi_002dthreaded-applications



More information about the Gcrypt-devel mailing list