1libcurl-thread(3)                   libcurl                  libcurl-thread(3)
2
3
4

NAME

6       libcurl-thread - libcurl thread safety
7

Multi-threading with libcurl

9       libcurl  is thread safe but has no internal thread synchronization. You
10       may have to provide your own locking should you meet any of the  thread
11       safety exceptions below.
12
13

Handles

15       You must never share the same handle in multiple threads.  You can pass
16       the handles around among threads, but you must never use a single  han‐
17       dle from more than one thread at any given time.
18

Shared objects

20       You  can share certain data between multiple handles by using the share
21       interface but you must provide your own locking and set  curl_share_se‐
22       topt(3) CURLSHOPT_LOCKFUNC and CURLSHOPT_UNLOCKFUNC.
23
24       Note  that some items are specifically documented as not thread-safe in
25       the share API (the connection pool and HSTS cache for example).
26

TLS

28       If you are accessing HTTPS or FTPS URLs in a multi-threaded manner, you
29       are  then of course using the underlying SSL library multi-threaded and
30       those libs might have their own requirements on  this  issue.  You  may
31       need to provide one or two functions to allow it to function properly:
32
33       OpenSSL
34              OpenSSL  1.1.0+  "can  be safely used in multi-threaded applica‐
35              tions provided that support for the underlying OS threading  API
36              is  built-in."  In  that case the engine is used by libcurl in a
37              way that is fully thread-safe.
38
39              https://www.openssl.org/docs/man1.1.0/man3/CRYPTO_THREAD_run_once.html#DE‐
40              SCRIPTION
41
42              OpenSSL <= 1.0.2 the user must set callbacks.
43
44              https://www.openssl.org/docs/man1.0.2/man3/CRYPTO_set_lock
45              ing_callback.html#DESCRIPTION
46
47              https://curl.se/libcurl/c/opensslthreadlock.html
48
49
50       GnuTLS https://gnutls.org/manual/html_node/Thread-safety.html
51
52       NSS    thread-safe already without anything required.
53
54       Secure-Transport
55              The engine is used by libcurl in a way  that  is  fully  thread-
56              safe.
57
58       Schannel
59              The  engine  is  used  by libcurl in a way that is fully thread-
60              safe.
61
62       wolfSSL
63              The engine is used by libcurl in a way  that  is  fully  thread-
64              safe.
65
66       BoringSSL
67              The  engine  is  used  by libcurl in a way that is fully thread-
68              safe.
69
70       AWS-LC The engine is used by libcurl in a way  that  is  fully  thread-
71              safe.
72

Signals

74       Signals  are  used  for  timing out name resolves (during DNS lookup) -
75       when built without using either the c-ares or threaded  resolver  back‐
76       ends.  When  using  multiple  threads you should set the CURLOPT_NOSIG‐
77       NAL(3) option to 1L for all handles. Everything will or might work fine
78       except  that timeouts are not honored during the DNS lookup - which you
79       can work around by building libcurl with  c-ares  or  threaded-resolver
80       support.  c-ares is a library that provides asynchronous name resolves.
81       On some platforms, libcurl simply will  not  function  properly  multi-
82       threaded unless the CURLOPT_NOSIGNAL(3) option is set.
83
84       When  CURLOPT_NOSIGNAL(3)  is set to 1L, your application needs to deal
85       with the risk of a SIGPIPE (that at least the OpenSSL backend can trig‐
86       ger).  Note  that  setting CURLOPT_NOSIGNAL(3) to 0L will not work in a
87       threaded situation as there will be race where libcurl risks  restoring
88       the former signal handler while another thread should still ignore it.
89

Name resolving

91       The  gethostbyname or getaddrinfo and other name resolving system calls
92       used by libcurl are provided by  your  operating  system  and  must  be
93       thread  safe. It is important that libcurl can find and use thread safe
94       versions of these and other system calls, as otherwise it cannot  func‐
95       tion fully thread safe. Some operating systems are known to have faulty
96       thread implementations. We have previously received problem reports  on
97       *BSD  (at least in the past, they may be working fine these days). Some
98       operating systems that are known to have solid and working thread  sup‐
99       port are Linux, Solaris and Windows.
100

curl_global_* functions

102       These  functions  are  thread-safe  since  libcurl  7.84.0 if curl_ver‐
103       sion_info(3) has the  CURL_VERSION_THREADSAFE  feature  bit  set  (most
104       platforms).
105
106       If  these  functions are not thread-safe and you are using libcurl with
107       multiple threads it is especially important that before  use  you  call
108       curl_global_init(3) or curl_global_init_mem(3) to explicitly initialize
109       the library and its dependents, rather than rely on  the  "lazy"  fail-
110       safe  initialization  that takes place the first time curl_easy_init(3)
111       is called. For an in-depth  explanation  refer  to  libcurl(3)  section
112       GLOBAL CONSTANTS.
113

Memory functions

115       These  functions,  provided either by your operating system or your own
116       replacements, must be thread safe. You can use  curl_global_init_mem(3)
117       to set your own replacement memory functions.
118

Non-safe functions

120       CURLOPT_DNS_USE_GLOBAL_CACHE(3) is not thread-safe.
121
122       curl_version_info(3) is not thread-safe before libcurl initialization.
123
124
125
126libcurl 8.2.1                   April 26, 2023               libcurl-thread(3)
Impressum