#include #include #include #include #include #include #include void *test_getaddrinfo(void *av) { struct addrinfo *addrinfo; pthread_t *thread_id = av; int i; for (i = 0; ; i += 1) { getaddrinfo("example.com", "80", NULL, &addrinfo); if (i % 100 == 42) { printf("[%d] Fap %d!\n", thread_id, i); } } } int main(int ac, char **av) { pthread_t *threads_ids; int nb_threads; void *thread_retval; if (ac < 2) { fprintf(stderr, "Usage: %s NB_THREADS\n", av[0]); return EXIT_FAILURE; } nb_threads = atoi(av[1]) - 1; threads_ids = calloc(nb_threads, sizeof(*threads_ids)); for (; nb_threads >= 0; nb_threads--) { if (pthread_create(&threads_ids[nb_threads], NULL, test_getaddrinfo, &threads_ids[nb_threads]) != 0) perror("pthread_create"); } pthread_join(threads_ids[0], &thread_retval); return 0; }