doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
multithread.c
Go to the documentation of this file.
1 /*****************************************************************************
2  * _ _ ____ _
3  * Project ___| | | | _ \| |
4  * / __| | | | |_) | |
5  * | (__| |_| | _ <| |___
6  * \___|\___/|_| \_\_____|
7  *
8  * $Id: multithread.c,v 1.1 2001/05/04 09:35:43 bagder Exp $
9  */
10 
11 /* A multi-threaded example that uses pthreads extensively to fetch
12  * X remote files at once */
13 
14 #include <stdio.h>
15 #include <pthread.h>
16 #include <curl/curl.h>
17 
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"
24 };
25 
26 void *pull_one_url(void *url)
27 {
28  CURL *curl;
29 
30  curl = curl_easy_init();
31 
32  curl_easy_setopt(curl, CURLOPT_URL, url);
33  curl_easy_perform(curl);
34 
35  curl_easy_cleanup(curl);
36 
37  return NULL;
38 }
39 
40 
41 /*
42  int pthread_create(pthread_t *new_thread_ID,
43  const pthread_attr_t *attr,
44  void * (*start_func)(void *), void *arg);
45 */
46 
47 int main(int argc, char **argv)
48 {
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 */
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]);
61  }
62 
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);
67  }
68 
69  return 0;
70 }
char * urls[]
Definition: multithread.c:19
void * pull_one_url(void *url)
Definition: multithread.c:26
CURLcode curl_easy_perform(CURL *curl)
Definition: easy.c:260
CURLcode curl_easy_setopt(CURL *curl, CURLoption option,...)
Definition: easy.c:217
int i
Definition: process.py:33
int main(int argc, char **argv)
Definition: multithread.c:47
#define NULL
Definition: Lib.h:88
void CURL
Definition: types.h:25
void curl_easy_cleanup(CURL *curl)
Definition: easy.c:288
CURL * curl_easy_init(void)
Definition: easy.c:195