aboutsummaryrefslogtreecommitdiff
path: root/docs/examples/threaded-ssl.c
diff options
context:
space:
mode:
authorDan Fandrich <dan@coneharvesters.com>2008-04-03 20:28:32 +0000
committerDan Fandrich <dan@coneharvesters.com>2008-04-03 20:28:32 +0000
commitbf52cef16fd2cc1ad83f760059d27f49f036c3eb (patch)
tree8cc62150d2ff3c5662130f0490cd720d5a5a62dc /docs/examples/threaded-ssl.c
parent16a9c5e02be15c1dde3aa21b3ced5a71c6fae53c (diff)
Made sure that curl_global_init is called in all the multithreaded
example programs.
Diffstat (limited to 'docs/examples/threaded-ssl.c')
-rw-r--r--docs/examples/threaded-ssl.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/docs/examples/threaded-ssl.c b/docs/examples/threaded-ssl.c
index c3455369b..afc609551 100644
--- a/docs/examples/threaded-ssl.c
+++ b/docs/examples/threaded-ssl.c
@@ -23,6 +23,8 @@
#include <pthread.h>
#include <curl/curl.h>
+#define NUMT 4
+
/* we have this global to let the callback get easy access to it */
static pthread_mutex_t *lockarray;
@@ -89,7 +91,7 @@ void init_locks(void)
#endif
/* List of URLs to fetch.*/
-const char *urls[]= {
+const char * const urls[]= {
"https://www.sf.net/",
"https://www.openssl.org/",
"https://www.sf.net/",
@@ -114,15 +116,18 @@ static void *pull_one_url(void *url)
int main(int argc, char **argv)
{
- pthread_t tid[4];
+ pthread_t tid[NUMT];
int i;
int error;
(void)argc; /* we don't use any arguments in this example */
(void)argv;
+ /* Must initialize libcurl before any threads are started */
+ curl_global_init(CURL_GLOBAL_ALL);
+
init_locks();
- for(i=0; i< 4; i++) {
+ for(i=0; i< NUMT; i++) {
error = pthread_create(&tid[i],
NULL, /* default attributes please */
pull_one_url,
@@ -134,7 +139,7 @@ int main(int argc, char **argv)
}
/* now wait for all threads to terminate */
- for(i=0; i< 4; i++) {
+ for(i=0; i< NUMT; i++) {
error = pthread_join(tid[i], NULL);
fprintf(stderr, "Thread %d terminated\n", i);
}