Imported Upstream version 7.50.2
[platform/upstream/curl.git] / docs / libcurl / libcurl-thread.3
1 .\" **************************************************************************
2 .\" *                                  _   _ ____  _
3 .\" *  Project                     ___| | | |  _ \| |
4 .\" *                             / __| | | | |_) | |
5 .\" *                            | (__| |_| |  _ <| |___
6 .\" *                             \___|\___/|_| \_\_____|
7 .\" *
8 .\" * Copyright (C) 2015 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
9 .\" *
10 .\" * This software is licensed as described in the file COPYING, which
11 .\" * you should have received as part of this distribution. The terms
12 .\" * are also available at https://curl.haxx.se/docs/copyright.html.
13 .\" *
14 .\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 .\" * copies of the Software, and permit persons to whom the Software is
16 .\" * furnished to do so, under the terms of the COPYING file.
17 .\" *
18 .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 .\" * KIND, either express or implied.
20 .\" *
21 .\" **************************************************************************
22 .\"
23 .TH libcurl-thread 3 "13 Jul 2015" "libcurl" "libcurl thread safety"
24 .SH NAME
25 libcurl-thread \- libcurl thread safety
26 .SH "Multi-threading with libcurl"
27 libcurl is thread safe but has no internal thread synchronization. You may have
28 to provide your own locking should you meet any of the thread safety exceptions
29 below.
30
31 \fBHandles.\fP You must \fBnever\fP share the same handle in multiple threads.
32 You can pass the handles around among threads, but you must never use a single
33 handle from more than one thread at any given time.
34
35 \fBShared objects.\fP You can share certain data between multiple handles by
36 using the share interface but you must provide your own locking and set
37 \fIcurl_share_setopt(3)\fP CURLSHOPT_LOCKFUNC and CURLSHOPT_UNLOCKFUNC.
38 .SH TLS
39 If you are accessing HTTPS or FTPS URLs in a multi-threaded manner, you are
40 then of course using the underlying SSL library multi-threaded and those libs
41 might have their own requirements on this issue.  You may need to provide one
42 or two functions to allow it to function properly:
43 .IP OpenSSL
44 OpenSSL 1.1.0 "can be safely used in multi-threaded applications provided that
45 support for the underlying OS threading API is built-in."
46
47 https://www.openssl.org/docs/manmaster/crypto/threads.html#DESCRIPTION
48
49 OpenSSL <= 1.0.2 the user must set callbacks.
50
51 https://www.openssl.org/docs/man1.0.2/crypto/threads.html#DESCRIPTION
52
53 https://curl.haxx.se/libcurl/c/opensslthreadlock.html
54
55 .IP GnuTLS
56 http://gnutls.org/manual/html_node/Thread-safety.html
57 .IP NSS
58 thread-safe already without anything required.
59 .IP PolarSSL
60 Required actions unknown.
61 .IP yassl
62 Required actions unknown.
63 .IP axTLS
64 Required actions unknown.
65 .IP Secure-Transport
66 The engine is used by libcurl in a way that is fully thread-safe.
67 .IP WinSSL
68 The engine is used by libcurl in a way that is fully thread-safe.
69 .IP wolfSSL
70 The engine is used by libcurl in a way that is fully thread-safe.
71 .IP BoringSSL
72 The engine is used by libcurl in a way that is fully thread-safe.
73 .SH "Other areas of caution"
74 .IP Signals
75 Signals are used for timing out name resolves (during DNS lookup) - when built
76 without using either the c-ares or threaded resolver backends. When using
77 multiple threads you should set the \fICURLOPT_NOSIGNAL(3)\fP option to 1L for
78 all handles. Everything will or might work fine except that timeouts are not
79 honored during the DNS lookup - which you can work around by building libcurl
80 with c-ares support. c-ares is a library that provides asynchronous name
81 resolves. On some platforms, libcurl simply will not function properly
82 multi-threaded unless this option is set.
83 .IP "Name resolving"
84 \fBgethostby* functions and other system calls.\fP These functions, provided
85 by your operating system, must be thread safe. It is very important that
86 libcurl can find and use thread safe versions of these and other system calls,
87 as otherwise it can't function fully thread safe. Some operating systems are
88 known to have faulty thread implementations. We have previously received
89 problem reports on *BSD (at least in the past, they may be working fine these
90 days).  Some operating systems that are known to have solid and working thread
91 support are Linux, Solaris and Windows.
92 .IP "curl_global_* functions"
93 These functions are not thread safe. If you are using libcurl with multiple
94 threads it is especially important that before use you call
95 \fIcurl_global_init(3)\fP or \fIcurl_global_init_mem(3)\fP to explicitly
96 initialize the library and its dependents, rather than rely on the "lazy"
97 fail-safe initialization that takes place the first time
98 \fIcurl_easy_init(3)\fP is called. For an in-depth explanation refer to
99 \fIlibcurl(3)\fP section \fBGLOBAL CONSTANTS\fP.
100 .IP "Memory functions"
101 These functions, provided either by your operating system or your own
102 replacements, must be thread safe. You can use \fIcurl_global_init_mem(3)\fP
103 to set your own replacement memory functions.
104 .IP "Non-safe functions"
105 \fICURLOPT_DNS_USE_GLOBAL_CACHE(3)\fP is not thread-safe.