1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * $Id: multithread.c,v 1.1 2005-06-24 13:02:16 andy Exp $
11 /* A multi-threaded example that uses pthreads extensively to fetch
12 * X remote files at once */
16 #include <curl/curl.h>
18 /* silly list of test-URLs */
20 "http://curl.haxx.se/",
21 "ftp://cool.haxx.se/",
22 "http://www.contactor.se/",
26 void *pull_one_url(void *url
)
30 curl
= curl_easy_init();
32 curl_easy_setopt(curl
, CURLOPT_URL
, url
);
33 curl_easy_perform(curl
);
35 curl_easy_cleanup(curl
);
42 int pthread_create(pthread_t *new_thread_ID,
43 const pthread_attr_t *attr,
44 void * (*start_func)(void *), void *arg);
47 int main(int argc
, char **argv
)
53 error
= pthread_create(&tid
[i
],
54 NULL
, /* default attributes please */
58 fprintf(stderr
, "Couldn't run thread number %d, errno %d\n", i
, error
);
60 fprintf(stderr
, "Thread %d, gets %s\n", i
, urls
[i
]);
63 /* now wait for all threads to terminate */
65 error
= pthread_join(tid
[i
], NULL
);
66 fprintf(stderr
, "Thread %d terminated\n", i
);