tool-chain:toolchain
wild-card:wildcard
wild card:wildcard
+\bthread ?safe[^."t]:thread-safe
+\bthread ?unsafe[^."t]:thread-unsafe
+multi ?thread:multi-thread
\bit's:it is
aren't:are not
can't:cannot
o example: fix formatting nits [232]
o examples/crawler: fix variable [92]
o examples/multi-uv: fix invalid req->data access [177]
- o examples/multithread: fix race condition [101]
+ o examples/threaded: fix race condition [101]
o examples: fix minor typo [203]
o examples: make functions/data static where missing [139]
o examples: tidy-up headers and includes [138]
multi-post
multi-single
multi-uv
-multithread
netrc
parseurl
persistent
smtp-vrfy
sslbackend
synctime
+threaded
threaded-ssl
unixsocket
url2file
COMPLICATED_MAY_BUILD = \
cacertinmem.c \
multi-uv.c \
- multithread.c \
sessioninfo.c \
+ threaded.c \
threaded-ssl.c \
usercertinmem.c
known_offset = 1;
}
secs = epoch_offset + tv.tv_sec;
- now = localtime(&secs); /* not thread safe but we do not care */
+ now = localtime(&secs); /* not thread-safe but we do not care */
snprintf(timebuf, sizeof(timebuf), "%02d:%02d:%02d.%06ld",
now->tm_hour, now->tm_min, now->tm_sec, (long)tv.tv_usec);
+++ /dev/null
-/***************************************************************************
- * _ _ ____ _
- * Project ___| | | | _ \| |
- * / __| | | | |_) | |
- * | (__| |_| | _ <| |___
- * \___|\___/|_| \_\_____|
- *
- * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
- *
- * This software is licensed as described in the file COPYING, which
- * you should have received as part of this distribution. The terms
- * are also available at https://curl.se/docs/copyright.html.
- *
- * You may opt to use, copy, modify, merge, publish, distribute and/or sell
- * copies of the Software, and permit persons to whom the Software is
- * furnished to do so, under the terms of the COPYING file.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- * SPDX-License-Identifier: curl
- *
- ***************************************************************************/
-/* <DESC>
- * A multi-threaded program using pthreads to fetch several files at once
- * </DESC>
- */
-
-/* Requires: HAVE_PTHREAD_H */
-
-#include <stdio.h>
-
-#include <pthread.h>
-
-#include <curl/curl.h>
-
-#define NUMT 4
-
-/*
- List of URLs to fetch.
-
- If you intend to use an SSL-based protocol here you might need to setup TLS
- library mutex callbacks as described here:
-
- https://curl.se/libcurl/c/threadsafe.html
-
-*/
-static const char * const urls[NUMT] = {
- "https://curl.se/",
- "ftp://example.com/",
- "https://example.net/",
- "www.example"
-};
-
-struct targ {
- const char *url;
-};
-
-static void *pull_one_url(void *p)
-{
- CURL *curl;
- struct targ *targ = p;
-
- curl = curl_easy_init();
- if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, targ->url);
- (void)curl_easy_perform(curl); /* ignores error */
- curl_easy_cleanup(curl);
- }
-
- return NULL;
-}
-
-/*
- int pthread_create(pthread_t *new_thread_ID,
- const pthread_attr_t *attr,
- void * (*start_func)(void *), void *arg);
-*/
-
-int main(void)
-{
- CURLcode res;
- pthread_t tid[NUMT];
- struct targ targs[NUMT];
- int i;
-
- /* Must initialize libcurl before any threads are started */
- res = curl_global_init(CURL_GLOBAL_ALL);
- if(res)
- return (int)res;
-
- for(i = 0; i < NUMT; i++) {
- int error;
- targs[i].url = urls[i];
- error = pthread_create(&tid[i],
- NULL, /* default attributes please */
- pull_one_url,
- (void *)&targs[i]);
- if(error)
- fprintf(stderr, "Could not run thread number %d, errno %d\n", i, error);
- else
- fprintf(stderr, "Thread %d, gets %s\n", i, urls[i]);
- }
-
- /* now wait for all threads to terminate */
- for(i = 0; i < NUMT; i++) {
- pthread_join(tid[i], NULL);
- fprintf(stderr, "Thread %d terminated\n", i);
- }
- curl_global_cleanup();
- return 0;
-}
*
***************************************************************************/
/* <DESC>
- * A multi threaded application that uses a progress bar to show
- * status. It uses Gtk+ to make a smooth pulse.
+ * A multi-threaded application that uses a progress bar to show
+ * status. It uses Gtk+ to make a smooth pulse.
* </DESC>
*/
/*
/* A multi-threaded example that uses pthreads and fetches 4 remote files at
* once over HTTPS.
*
- * Recent versions of OpenSSL and GnuTLS are thread safe by design, assuming
+ * Recent versions of OpenSSL and GnuTLS are thread-safe by design, assuming
* support for the underlying OS threading API is built-in. Older revisions
* of this example demonstrated locking callbacks for the SSL library, which
* are no longer necessary. An older revision with callbacks can be found at
/* Also requires TLS support to run */
#include <stdio.h>
+
#include <pthread.h>
+
#include <curl/curl.h>
#define NUMT 4
--- /dev/null
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at https://curl.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * SPDX-License-Identifier: curl
+ *
+ ***************************************************************************/
+/* <DESC>
+ * A multi-threaded program using pthreads to fetch several files at once
+ * </DESC>
+ */
+
+/* Requires: HAVE_PTHREAD_H */
+
+#include <stdio.h>
+
+#include <pthread.h>
+
+#include <curl/curl.h>
+
+#define NUMT 4
+
+/*
+ List of URLs to fetch.
+
+ If you intend to use an SSL-based protocol here you might need to setup TLS
+ library mutex callbacks as described here:
+
+ https://curl.se/libcurl/c/threadsafe.html
+
+*/
+static const char * const urls[NUMT] = {
+ "https://curl.se/",
+ "ftp://example.com/",
+ "https://example.net/",
+ "www.example"
+};
+
+struct targ {
+ const char *url;
+};
+
+static void *pull_one_url(void *p)
+{
+ CURL *curl;
+ struct targ *targ = p;
+
+ curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, targ->url);
+ (void)curl_easy_perform(curl); /* ignores error */
+ curl_easy_cleanup(curl);
+ }
+
+ return NULL;
+}
+
+/*
+ int pthread_create(pthread_t *new_thread_ID,
+ const pthread_attr_t *attr,
+ void * (*start_func)(void *), void *arg);
+*/
+
+int main(void)
+{
+ CURLcode res;
+ pthread_t tid[NUMT];
+ struct targ targs[NUMT];
+ int i;
+
+ /* Must initialize libcurl before any threads are started */
+ res = curl_global_init(CURL_GLOBAL_ALL);
+ if(res)
+ return (int)res;
+
+ for(i = 0; i < NUMT; i++) {
+ int error;
+ targs[i].url = urls[i];
+ error = pthread_create(&tid[i],
+ NULL, /* default attributes please */
+ pull_one_url,
+ (void *)&targs[i]);
+ if(error)
+ fprintf(stderr, "Could not run thread number %d, errno %d\n", i, error);
+ else
+ fprintf(stderr, "Thread %d, gets %s\n", i, urls[i]);
+ }
+
+ /* now wait for all threads to terminate */
+ for(i = 0; i < NUMT; i++) {
+ pthread_join(tid[i], NULL);
+ fprintf(stderr, "Thread %d terminated\n", i);
+ }
+
+ curl_global_cleanup();
+
+ return 0;
+}
thread in the program (i.e. a thread sharing the same memory) is running.
This does not just mean no other thread that is using libcurl. Because
curl_global_cleanup(3) calls functions of other libraries that are
-similarly thread unsafe, it could conflict with any other thread that uses
+similarly thread-unsafe, it could conflict with any other thread that uses
these other libraries.
See the description in libcurl(3) of global environment requirements for
call this function when any other thread in the program (i.e. a thread sharing
the same memory) is running. This does not just mean no other thread that is
using libcurl. Because curl_global_init(3) calls functions of other libraries
-that are similarly thread unsafe, it could conflict with any other thread that
+that are similarly thread-unsafe, it could conflict with any other thread that
uses these other libraries.
If you are initializing libcurl from a Windows DLL you should not initialize
thread in the program (i.e. a thread sharing the same memory) is running. This
does not just mean no other thread that is using libcurl. Because
curl_global_init(3) may call functions of other libraries that are similarly
-thread unsafe, it could conflict with any other thread that uses these other
+thread-unsafe, it could conflict with any other thread that uses these other
libraries.
If you are initializing libcurl from a Windows DLL you should not initialize
# Multi-threading with libcurl
-libcurl is thread safe but has no internal thread synchronization. You may have
+libcurl is thread-safe but has no internal thread synchronization. You may have
to provide your own locking should you meet any of the thread safety exceptions
below.
# Name resolving
The **gethostbyname** or **getaddrinfo** and other name resolving system
-calls used by libcurl are provided by your operating system and must be thread
-safe. It is important that libcurl can find and use thread safe versions of
-these and other system calls, as otherwise it cannot function fully thread
-safe. Some operating systems are known to have faulty thread
+calls used by libcurl are provided by your operating system and must be
+thread-safe. It is important that libcurl can find and use thread-safe versions
+of these and other system calls, as otherwise it cannot function fully
+thread-safe. Some operating systems are known to have faulty thread
implementations. We have previously received problem reports on *BSD (at least
in the past, they may be working fine these days). Some operating systems that
are known to have solid and working thread support are Linux, Solaris and
# Memory functions
These functions, provided either by your operating system or your own
-replacements, must be thread safe. You can use curl_global_init_mem(3)
+replacements, must be thread-safe. You can use curl_global_init_mem(3)
to set your own replacement memory functions.
# Non-safe functions
# Multi-threading Issues
-libcurl is thread safe but there are a few exceptions. Refer to
+libcurl is thread-safe but there are a few exceptions. Refer to
libcurl-thread(3) for more information.
# When It does not Work
# THREADS
-libcurl is thread safe but there are a few exceptions. Refer to
+libcurl is thread-safe but there are a few exceptions. Refer to
libcurl-thread(3) for more information.
# PERSISTENT CONNECTIONS
curl_version_info(3) has the CURL_VERSION_THREADSAFE feature bit set
(most platforms). Read libcurl-thread(3) for thread safety guidelines.
-If the global constant functions are *not thread safe*, then you must
+If the global constant functions are *not thread-safe*, then you must
not call them when any other thread in the program is running. It
is not good enough that no other thread is using libcurl at the time,
because these functions internally call similar functions of other
generally know what these libraries are, or whether other threads are
using them.
-If the global constant functions are *not thread safe*, then the basic rule
+If the global constant functions are *not thread-safe*, then the basic rule
for constructing a program that uses libcurl is this: Call
curl_global_init(3), with a *CURL_GLOBAL_ALL* argument, immediately
after the program starts, while it is still only one thread and before it uses
if(curl) {
CURLcode ret;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- /* switch off the use of a global, thread unsafe, cache */
+ /* switch off the use of a global, thread-unsafe, cache */
curl_easy_setopt(curl, CURLOPT_DNS_USE_GLOBAL_CACHE, 0L);
ret = curl_easy_perform(curl);
curl_easy_cleanup(curl);
* Creates a new curl session handle with the same options set for the handle
* passed in. Duplicating a handle could only be a matter of cloning data and
* options, internal state info and things like persistent connections cannot
- * be transferred. It is useful in multithreaded applications when you can run
+ * be transferred. It is useful in multi-threaded applications when you can run
* curl_easy_duphandle() for each new thread to avoid a series of identical
* curl_easy_setopt() invokes in every thread.
*/
* Because we need to handle the different cases in hostip4.c at runtime,
* not at compile-time, based on what was detected in Curl_amiga_init(),
* we replace it completely with our own as to not complicate the baseline
- * code. Assumes malloc/calloc/free are thread safe because Curl_he2ai()
+ * code. Assumes malloc/calloc/free are thread-safe because Curl_he2ai()
* allocates memory also.
*/
}
else {
#ifdef CURLRES_THREADED
- /* gethostbyname() is not thread safe, so we need to reopen bsdsocket
+ /* gethostbyname() is not thread-safe, so we need to reopen bsdsocket
* on the thread's context
*/
struct Library *base = OpenLibrary("bsdsocket.library", 4);
/* OS400 supports a 3-argument ASCII version of gethostbyaddr_r(), but its
* prototype is incompatible with the "standard" one (1st argument is not
* const). However, getaddrinfo() is supported (ASCII version defined as
- * a local wrapper in setup-os400.h) in a threadsafe way: we can then
+ * a local wrapper in setup-os400.h) in a thread-safe way: we can then
* configure getaddrinfo() as such and get rid of gethostbyname_r() without
- * loss of threadsafeness. */
+ * loss of thread-safeness. */
#undef HAVE_GETHOSTBYNAME_R
#undef HAVE_GETHOSTBYNAME_R_3
#undef HAVE_GETHOSTBYNAME_R_5
/* clear the DNS cache */
void Curl_dnscache_clear(struct Curl_easy *data);
-/* IPv4 threadsafe resolve function used for synch and asynch builds */
+/* IPv4 thread-safe resolve function used for synch and asynch builds */
struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, int port);
CURLcode Curl_once_resolved(struct Curl_easy *data,
#if defined(CURLRES_IPV4) && !defined(CURLRES_ARES) && !defined(CURLRES_AMIGA)
/*
- * Curl_ipv4_resolve_r() - ipv4 threadsafe resolver function.
+ * Curl_ipv4_resolve_r() - ipv4 thread-safe resolver function.
*
* This is used for both synchronous and asynchronous resolver builds,
- * implying that only threadsafe code and function calls may be used.
+ * implying that only thread-safe code and function calls may be used.
*
*/
struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname,
&h_errnop);
/* If the buffer is too small, it returns NULL and sets errno to
- * ERANGE. The errno is thread safe if this is compiled with
+ * ERANGE. The errno is thread-safe if this is compiled with
* -D_REENTRANT as then the 'errno' variable is a macro defined to get
* used properly for threads.
*/
#else /* (HAVE_GETADDRINFO && HAVE_GETADDRINFO_THREADSAFE) ||
HAVE_GETHOSTBYNAME_R */
/*
- * Here is code for platforms that do not have a thread safe
+ * Here is code for platforms that do not have a thread-safe
* getaddrinfo() nor gethostbyname_r() function or for which
* gethostbyname() is the preferred one.
*/
#ifdef USE_WINDOWS_SSPI
if(!Curl_pSecFn) {
- /* not thread safe and leaks - use curl_global_init() to avoid */
+ /* not thread-safe and leaks - use curl_global_init() to avoid */
CURLcode err = Curl_sspi_global_init();
if(!Curl_pSecFn)
return err;
* For advanced analysis, record a log file and write perl scripts to analyze
* them!
*
- * Do not use these with multithreaded test programs!
+ * Do not use these with multi-threaded test programs!
*/
FILE *curl_dbg_logfile = NULL;
* gtls_init()
*
* Global GnuTLS init, called from Curl_ssl_init(). This calls functions that
- * are not thread-safe (It is thread safe since GnuTLS 3.3.0) and thus this
+ * are not thread-safe (It is thread-safe since GnuTLS 3.3.0) and thus this
* function itself is not thread-safe and must only be called from within
* curl_global_init() to keep the thread situation under control!
*
dnl with shell variable curl_disallow_getaddrinfo, then
dnl HAVE_GETADDRINFO will be defined. Additionally when
dnl HAVE_GETADDRINFO gets defined this will also attempt
-dnl to find out if getaddrinfo happens to be threadsafe,
+dnl to find out if getaddrinfo happens to be thread-safe,
dnl defining HAVE_GETADDRINFO_THREADSAFE when true.
AC_DEFUN([CURL_CHECK_FUNC_GETADDRINFO], [
fi
#
if test "$curl_cv_func_getaddrinfo" = "yes"; then
- AC_MSG_CHECKING([if getaddrinfo is threadsafe])
+ AC_MSG_CHECKING([if getaddrinfo is thread-safe])
if test "$curl_cv_apple" = "yes"; then
dnl Darwin 6.0 and macOS 10.2.X and newer
tst_tsafe_getaddrinfo="yes"
AC_MSG_RESULT([$tst_tsafe_getaddrinfo])
if test "$tst_tsafe_getaddrinfo" = "yes"; then
AC_DEFINE_UNQUOTED(HAVE_GETADDRINFO_THREADSAFE, 1,
- [Define to 1 if the getaddrinfo function is threadsafe.])
+ [Define to 1 if the getaddrinfo function is thread-safe.])
curl_cv_func_getaddrinfo_threadsafe="yes"
else
curl_cv_func_getaddrinfo_threadsafe="no"
* SIGINT is not supported for any Win32 application. When a CTRL+C
* interrupt occurs, Win32 operating systems generate a new thread
* to specifically handle that interrupt. This can cause a single-thread
- * application, such as one in UNIX, to become multithreaded and cause
+ * application, such as one in UNIX, to become multi-threaded and cause
* unexpected behavior.
* [...]
* The SIGKILL and SIGTERM signals are not generated under Windows.