7e9866c12ba9eec915a3c6d87c44872d668afe38
[openssl.git] / doc / crypto / threads.pod
1 =pod
2
3 =head1 NAME
4
5 CRYPTO_set_locking_callback, CRYPTO_set_id_callback - OpenSSL thread support
6
7 =head1 SYNOPSIS
8
9  #include <openssl/crypto.h>
10
11  void CRYPTO_set_locking_callback(void (*locking_function)(int mode,
12         int n, const char *file, int line));
13
14  void CRYPTO_set_id_callback(unsigned long (*id_function)(void));
15
16 =head1 DESCRIPTION
17
18 OpenSSL can safely be used in multi-threaded applications provided
19 that two callback functions are set.
20
21 locking_function(int mode, int type, const char *file, int line) is
22 needed to perform locking on shared data stuctures. Multi-threaded
23 applications will crash at random if it is not set.
24
25 locking_function() must be able to handle up to B<CRYPTO_NUM_LOCKS>
26 different mutex locks. It sets the B<n>th lock if B<mode> &
27 B<CRYPTO_LOCK>, and releases it otherwise.
28
29 B<file> and B<line> are the file number of the function setting the
30 lock. They can be useful for debugging.
31
32 id_function(void) is a function that returns a thread ID. It is not
33 needed on Windows nor on platforms where getpid() returns a different
34 ID for each thread.
35
36 =NOTE
37
38 You can find out if OpenSSL was configured with thread support:
39
40  #define OPENSSL_THREAD_DEFINES
41  #include <openssl/opensslconf.h>
42  #if defined(THREADS)
43    // thread support enabled
44  #else
45    // no thread support
46  #endif
47
48 =head1 EXAMPLES
49
50 B<crypto/threads/mttest.c> shows examples of the callback functions on
51 Solaris, Irix and Win32.
52
53 =head1 HISTORY
54
55 CRYPTO_set_locking_callback() and CRYPTO_set_id_callback() are
56 available in all versions of SSLeay and OpenSSL.
57
58 =head1 SEE ALSO
59
60 L<crypto(3)|crypto(3)>
61
62 =cut