/////////////////////////////////////////////////////////////////////////////// /// satthread.c /////////////////////////////////////////////////////////////// /* * satthread - Create child thread and join it several times. Each child thread * does nothing and exits immediately. * * Copyright (C) 2007 Satoru Takeuchi * * This software may be used and distributed according to the terms * of the GNU General Public License, incorporated herein by reference. */ #include #include #include #include #define NTHREAD 10 static void *thread_fn(void *arg) { return NULL; } static void *creator(void* arg) { int i; pthread_t t; for (i = 0; i < NTHREAD; i++) { if (pthread_create(&t, NULL, thread_fn, NULL)) { fprintf(stderr, "pthread_create(%d) failed\n", i); exit(EXIT_FAILURE); } usleep(100 * 1000); pthread_join(t, NULL); } } int main(int argc, char **argv) { int i; pthread_t t; if (pthread_create(&t, NULL, creator, NULL)) { fprintf(stderr, "pthread_create (creator) failed\n"); exit(EXIT_FAILURE); } pthread_join(t, NULL); exit(EXIT_SUCCESS); }