Back to index

glibc  2.9
ex6.c
Go to the documentation of this file.
00001 #include <errno.h>
00002 #include <stdio.h>
00003 #include <string.h>
00004 #include <pthread.h>
00005 #include <unistd.h>
00006 
00007 static void *
00008 test_thread (void *v_param)
00009 {
00010   return NULL;
00011 }
00012 
00013 int
00014 main (void)
00015 {
00016   unsigned long count;
00017 
00018   setvbuf (stdout, NULL, _IONBF, 0);
00019 
00020   for (count = 0; count < 2000; ++count)
00021     {
00022       pthread_t thread;
00023       int status;
00024 
00025       status = pthread_create (&thread, NULL, test_thread, NULL);
00026       if (status != 0)
00027        {
00028          printf ("status = %d, count = %lu: %s\n", status, count,
00029                 strerror (errno));
00030          return 1;
00031        }
00032       else
00033        {
00034          printf ("count = %lu\n", count);
00035        }
00036       /* pthread_detach (thread); */
00037       int err = pthread_join (thread, NULL);
00038       if (err != 0)
00039        {
00040          printf ("join failed (%s), count %lu\n", strerror (err), count);
00041          return 2;
00042        }
00043       usleep (10);
00044     }
00045   return 0;
00046 }