View difference between Paste ID: cWZphPK7 and 4QeFCgvV
SHOW: | | - or go back to the newest paste.
1
#include <sys/types.h>
2
#include <sys/socket.h>
3
#include <netdb.h>
4
#include <stdlib.h>
5
#include <unistd.h>
6
#include <stdio.h>
7
#include <pthread.h>
8
9
void *test_getaddrinfo(void *av)
10
{
11
  struct addrinfo *addrinfo;
12
  pthread_t *thread_id = av;
13
  int i;
14
15
  for (i = 0; ; i += 1)
16
    {
17-
      getaddrinfo("teddy.melty.fr", "80", NULL, &addrinfo);
17+
      getaddrinfo("example.com", "80", NULL, &addrinfo);
18
      if (i % 100 == 42)
19
        {
20
          printf("[%d] Fap %d!\n", thread_id, i);
21
        }
22
    }
23
}
24
25
26
int main(int ac, char **av)
27
{
28
  pthread_t *threads_ids;
29
  int nb_threads;
30
  void *thread_retval;
31
32
  if (ac < 2)
33
    {
34
      fprintf(stderr, "Usage: %s NB_THREADS\n", av[0]);
35
      return EXIT_FAILURE;
36
    }
37
  nb_threads = atoi(av[1]) - 1;
38
  threads_ids = calloc(nb_threads, sizeof(*threads_ids));
39
  for (; nb_threads >= 0; nb_threads--)
40
    {
41
      if (pthread_create(&threads_ids[nb_threads], NULL, test_getaddrinfo, &threads_ids[nb_threads]) != 0)
42
        perror("pthread_create");
43
    }
44
  pthread_join(threads_ids[0], &thread_retval);
45
  return 0;
46
}