aacc75fdf00e060e43ba744d149a40388b006221
[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 https://www.openssl.org/docs/crypto/threads.html#DESCRIPTION
45
46 https://curl.haxx.se/libcurl/c/opensslthreadlock.html
47 .IP GnuTLS
48 http://gnutls.org/manual/html_node/Thread-safety.html
49 .IP NSS
50 thread-safe already without anything required.
51 .IP PolarSSL
52 Required actions unknown.
53 .IP yassl
54 Required actions unknown.
55 .IP axTLS
56 Required actions unknown.
57 .IP Secure-Transport
58 The engine is used by libcurl in a way that is fully thread-safe.
59 .IP WinSSL
60 The engine is used by libcurl in a way that is fully thread-safe.
61 .IP wolfSSL
62 The engine is used by libcurl in a way that is fully thread-safe.
63 .SH "Other areas of caution"
64 .IP Signals
65 Signals are used for timing out name resolves (during DNS lookup) - when built
66 without using either the c-ares or threaded resolver backends. When using
67 multiple threads you should set the \fICURLOPT_NOSIGNAL(3)\fP option to 1L for
68 all handles. Everything will or might work fine except that timeouts are not
69 honored during the DNS lookup - which you can work around by building libcurl
70 with c-ares support. c-ares is a library that provides asynchronous name
71 resolves. On some platforms, libcurl simply will not function properly
72 multi-threaded unless this option is set.
73 .IP "Name resolving"
74 \fBgethostby* functions and other system calls.\fP These functions, provided
75 by your operating system, must be thread safe. It is very important that
76 libcurl can find and use thread safe versions of these and other system calls,
77 as otherwise it can't function fully thread safe. Some operating systems are
78 known to have faulty thread implementations. We have previously received
79 problem reports on *BSD (at least in the past, they may be working fine these
80 days).  Some operating systems that are known to have solid and working thread
81 support are Linux, Solaris and Windows.
82 .IP "curl_global_* functions"
83 These functions are not thread safe. If you are using libcurl with multiple
84 threads it is especially important that before use you call
85 \fIcurl_global_init(3)\fP or \fIcurl_global_init_mem(3)\fP to explicitly
86 initialize the library and its dependents, rather than rely on the "lazy"
87 fail-safe initialization that takes place the first time
88 \fIcurl_easy_init(3)\fP is called. For an in-depth explanation refer to
89 \fIlibcurl(3)\fP section \fBGLOBAL CONSTANTS\fP.
90 .IP "Memory functions"
91 These functions, provided either by your operating system or your own
92 replacements, must be thread safe. You can use \fIcurl_global_init_mem(3)\fP
93 to set your own replacement memory functions.
94 .IP "Non-safe functions"
95 \fICURLOPT_DNS_USE_GLOBAL_CACHE(3)\fP is not thread-safe.