[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
7.1.4 Thread safety
The GnuTLS library is thread safe by design, meaning that objects of the library such as TLS sessions, can be safely divided across threads as long as a single thread accesses a single object. This is sufficient to support a server which handles several sessions per thread. If, however, an object needs to be shared across threads then access must be protected with a mutex. Read-only access to objects, for example the credentials holding structures (see Authentication), is also thread-safe.
The random generator of the cryptographic back-end, is not thread safe and requires
mutex locks which are setup by GnuTLS.
Applications can either call gnutls_global_init which will initialize the default
operating system provided locks (i.e. pthreads
on GNU/Linux and
CriticalSection
on Windows), or specify manually the locking system using
the function gnutls_global_set_mutex before calling gnutls_global_init.
Setting manually mutexes is recommended
only to applications that have full control of the underlying libraries. If this
is not the case, the use of the operating system defaults is recommended. An example of
non-native thread usage is shown below.
#include <gnutls.h> /* Other thread packages */ int main() { gnutls_global_set_mutex (mutex_init, mutex_deinit, mutex_lock, mutex_unlock); gnutls_global_init(); }
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on January 4, 2012 using texi2html 5.0.