Back to index

glibc  2.9
tst-exit3.c
Go to the documentation of this file.
00001 #include <pthread.h>
00002 #include <signal.h>
00003 #include <stdio.h>
00004 #include <stdlib.h>
00005 #include <string.h>
00006 #include <unistd.h>
00007 
00008 
00009 static pthread_barrier_t b;
00010 
00011 
00012 static void *
00013 tf2 (void *arg)
00014 {
00015   while (1)
00016     sleep (100);
00017 
00018   /* NOTREACHED */
00019   return NULL;
00020 }
00021 
00022 
00023 static void *
00024 tf (void *arg)
00025 {
00026   pthread_t th;
00027 
00028   int e = pthread_barrier_wait (&b);
00029   if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
00030     {
00031       puts ("barrier_wait failed");
00032       exit (1);
00033     }
00034 
00035   e = pthread_create (&th, NULL, tf2, NULL);
00036   if (e != 0)
00037     {
00038       printf ("create failed: %s\n", strerror (e));
00039       exit (1);
00040     }
00041 
00042   /* Terminate only this thread.  */
00043   return NULL;
00044 }
00045 
00046 
00047 static int
00048 do_test (void)
00049 {
00050   pthread_t th;
00051 
00052   if (pthread_barrier_init (&b, NULL, 2) != 0)
00053     {
00054       puts ("barrier_init failed");
00055       exit (1);
00056     }
00057 
00058   int e = pthread_create (&th, NULL, tf, NULL);
00059   if (e != 0)
00060     {
00061       printf ("create failed: %s\n", strerror (e));
00062       exit (1);
00063     }
00064 
00065   e = pthread_barrier_wait (&b);
00066   if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
00067     {
00068       puts ("barrier_wait failed");
00069       exit (1);
00070     }
00071 
00072   /* Terminate only this thread.  */
00073   pthread_exit (NULL);
00074 
00075   /* NOTREACHED */
00076   return 1;
00077 }
00078 
00079 #define EXPECTED_SIGNAL SIGALRM
00080 #define TEST_FUNCTION do_test ()
00081 #include "../test-skeleton.c"