~ubuntu-branches/ubuntu/dapper/curl/dapper

« back to all changes in this revision

Viewing changes to docs/examples/multithread.c

  • Committer: Bazaar Package Importer
  • Author(s): Domenico Andreoli
  • Date: 2002-03-12 19:06:21 UTC
  • Revision ID: james.westby@ubuntu.com-20020312190621-iqx7k9cipo5d0ifr
Tags: upstream-7.9.5
ImportĀ upstreamĀ versionĀ 7.9.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 */
 
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]);
 
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
}