chiark / gitweb /
eglibc (2.11.3-4+deb6u3) squeeze-lts; urgency=medium
[eglibc.git] / nptl / tst-exit3.c
1 #include <pthread.h>
2 #include <signal.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <unistd.h>
7
8
9 static pthread_barrier_t b;
10
11
12 static void *
13 tf2 (void *arg)
14 {
15   while (1)
16     sleep (100);
17
18   /* NOTREACHED */
19   return NULL;
20 }
21
22
23 static void *
24 tf (void *arg)
25 {
26   pthread_t th;
27
28   int e = pthread_barrier_wait (&b);
29   if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
30     {
31       puts ("barrier_wait failed");
32       exit (1);
33     }
34
35   e = pthread_create (&th, NULL, tf2, NULL);
36   if (e != 0)
37     {
38       printf ("create failed: %s\n", strerror (e));
39       exit (1);
40     }
41
42   /* Terminate only this thread.  */
43   return NULL;
44 }
45
46
47 static int
48 do_test (void)
49 {
50   pthread_t th;
51
52   if (pthread_barrier_init (&b, NULL, 2) != 0)
53     {
54       puts ("barrier_init failed");
55       exit (1);
56     }
57
58   int e = pthread_create (&th, NULL, tf, NULL);
59   if (e != 0)
60     {
61       printf ("create failed: %s\n", strerror (e));
62       exit (1);
63     }
64
65   e = pthread_barrier_wait (&b);
66   if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
67     {
68       puts ("barrier_wait failed");
69       exit (1);
70     }
71
72   /* Terminate only this thread.  */
73   pthread_exit (NULL);
74
75   /* NOTREACHED */
76   return 1;
77 }
78
79 #define EXPECTED_SIGNAL SIGALRM
80 #define TEST_FUNCTION do_test ()
81 #include "../test-skeleton.c"