2.4 Thread safety
Although the GnuTLS library is thread safe by design, some
parts of the cryptographic back-end, such as the random generator, are not.
Applications can either call gnutls_global_init which will use 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. Examples
are shown below.
| | #include <gnutls.h>
/* Native threads
*/
int main()
{
gnutls_global_init();
}
|
| | #include <gnutls.h>
/* Other thread packages
*/
int main()
{
gnutls_global_mutex_set (mutex_init, mutex_deinit,
mutex_lock, mutex_unlock);
gnutls_global_init();
}
|