5 CRYPTO_set_locking_callback, CRYPTO_set_id_callback - OpenSSL thread support
9 #include <openssl/crypto.h>
11 void CRYPTO_set_locking_callback(void (*locking_function)(int mode,
12 int n, const char *file, int line));
14 void CRYPTO_set_id_callback(unsigned long (*id_function)(void));
18 OpenSSL can safely be used in multi-threaded applications provided
19 that two callback functions are set.
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.
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.
29 B<file> and B<line> are the file number of the function setting the
30 lock. They can be useful for debugging.
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
38 You can find out if OpenSSL was configured with thread support:
40 #define OPENSSL_THREAD_DEFINES
41 #include <openssl/opensslconf.h>
43 // thread support enabled
50 B<crypto/threads/mttest.c> shows examples of the callback functions on
51 Solaris, Irix and Win32.
55 CRYPTO_set_locking_callback() and CRYPTO_set_id_callback() are
56 available in all versions of SSLeay and OpenSSL.
60 L<crypto(3)|crypto(3)>