1libcurl-thread(3) libcurl thread safety libcurl-thread(3)
2
3
4
6 libcurl-thread - libcurl thread safety
7
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. You must never share the same handle in multiple threads. You
14 can pass the handles around among threads, but you must never use a
15 single handle from more than one thread at any given time.
16
17 Shared objects. You can share certain data between multiple handles by
18 using the share interface but you must provide your own locking and set
19 curl_share_setopt(3) CURLSHOPT_LOCKFUNC and CURLSHOPT_UNLOCKFUNC.
20
22 If you are accessing HTTPS or FTPS URLs in a multi-threaded manner, you
23 are then of course using the underlying SSL library multi-threaded and
24 those libs might have their own requirements on this issue. You may
25 need to provide one or two functions to allow it to function properly:
26
27 OpenSSL
28 OpenSSL 1.1.0+ "can be safely used in multi-threaded applica‐
29 tions provided that support for the underlying OS threading API
30 is built-in." In that case the engine is used by libcurl in a
31 way that is fully thread-safe.
32
33 https://www.openssl.org/docs/man1.1.0/man3/CRYPTO_THREAD_run_once.html#DESCRIP‐
34 TION
35
36 OpenSSL <= 1.0.2 the user must set callbacks.
37
38 https://www.openssl.org/docs/man1.0.2/man3/CRYPTO_set_lock‐
39 ing_callback.html#DESCRIPTION
40
41 https://curl.haxx.se/libcurl/c/opensslthreadlock.html
42
43
44 GnuTLS https://gnutls.org/manual/html_node/Thread-safety.html
45
46 NSS thread-safe already without anything required.
47
48 Secure-Transport
49 The engine is used by libcurl in a way that is fully thread-
50 safe.
51
52 WinSSL The engine is used by libcurl in a way that is fully thread-
53 safe.
54
55 wolfSSL
56 The engine is used by libcurl in a way that is fully thread-
57 safe.
58
59 BoringSSL
60 The engine is used by libcurl in a way that is fully thread-
61 safe.
62
64 Signals
65 Signals are used for timing out name resolves (during DNS
66 lookup) - when built without using either the c-ares or threaded
67 resolver backends. When using multiple threads you should set
68 the CURLOPT_NOSIGNAL(3) option to 1L for all handles. Everything
69 will or might work fine except that timeouts are not honored
70 during the DNS lookup - which you can work around by building
71 libcurl with c-ares or threaded-resolver support. c-ares is a
72 library that provides asynchronous name resolves. On some plat‐
73 forms, libcurl simply will not function properly multi-threaded
74 unless the CURLOPT_NOSIGNAL(3) option is set.
75
76 When CURLOPT_NOSIGNAL(3) is set to 1L, your application needs to
77 deal with the risk of a SIGPIPE (that at least the OpenSSL back‐
78 end can trigger). Note that setting CURLOPT_NOSIGNAL(3) to 0L
79 will not work in a threaded situation as there will be race
80 where libcurl risks restoring the former signal handler while
81 another thread should still ignore it.
82
83 Name resolving
84 gethostby* functions and other system calls. These functions,
85 provided by your operating system, must be thread safe. It is
86 very important that libcurl can find and use thread safe ver‐
87 sions of these and other system calls, as otherwise it can't
88 function fully thread safe. Some operating systems are known to
89 have faulty thread implementations. We have previously received
90 problem reports on *BSD (at least in the past, they may be work‐
91 ing fine these days). Some operating systems that are known to
92 have solid and working thread support are Linux, Solaris and
93 Windows.
94
95 curl_global_* functions
96 These functions are not thread safe. If you are using libcurl
97 with multiple threads it is especially important that before use
98 you call curl_global_init(3) or curl_global_init_mem(3) to
99 explicitly initialize the library and its dependents, rather
100 than rely on the "lazy" fail-safe initialization that takes
101 place the first time curl_easy_init(3) is called. For an in-
102 depth explanation refer to libcurl(3) section GLOBAL CONSTANTS.
103
104 Memory functions
105 These functions, provided either by your operating system or
106 your own replacements, must be thread safe. You can use
107 curl_global_init_mem(3) to set your own replacement memory func‐
108 tions.
109
110 Non-safe functions
111 CURLOPT_DNS_USE_GLOBAL_CACHE(3) is not thread-safe.
112
113
114
115libcurl 7.66.0 June 30, 2019 libcurl-thread(3)