Initial commit.
[CMakeLuaTailorHgBridge.git] / CMakeLua / Utilities / cmcurl / Testing / multithread.c
blobee4205f8db9087ae9baabe42d2d9025059e9f071
1 /*****************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * $Id: multithread.c,v 1.1 2005/06/24 13:02:16 andy Exp $
9 */
11 /* A multi-threaded example that uses pthreads extensively to fetch
12 * X remote files at once */
14 #include <stdio.h>
15 #include <pthread.h>
16 #include <curl/curl.h>
18 /* silly list of test-URLs */
19 char *urls[]= {
20 "http://curl.haxx.se/",
21 "ftp://cool.haxx.se/",
22 "http://www.contactor.se/",
23 "www.haxx.se"
26 void *pull_one_url(void *url)
28 CURL *curl;
30 curl = curl_easy_init();
32 curl_easy_setopt(curl, CURLOPT_URL, url);
33 curl_easy_perform(curl);
35 curl_easy_cleanup(curl);
37 return NULL;
41 /*
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)
49 pthread_t tid[4];
50 int i;
51 int error;
52 for(i=0; i< 4; i++) {
53 error = pthread_create(&tid[i],
54 NULL, /* default attributes please */
55 pull_one_url,
56 urls[i]);
57 if(0 != error)
58 fprintf(stderr, "Couldn't run thread number %d, errno %d\n", i, error);
59 else
60 fprintf(stderr, "Thread %d, gets %s\n", i, urls[i]);
63 /* now wait for all threads to terminate */
64 for(i=0; i< 4; i++) {
65 error = pthread_join(tid[i], NULL);
66 fprintf(stderr, "Thread %d terminated\n", i);
69 return 0;