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 static int do_test (void);
9
10 #define TEST_FUNCTION do_test ()
11 #include "../test-skeleton.c"
12
13 static pthread_barrier_t b;
14
15
16 static void *
tf2(void * arg)17 tf2 (void *arg)
18 {
19 while (1)
20 sleep (100);
21
22 /* NOTREACHED */
23 return NULL;
24 }
25
26
27 static void *
tf(void * arg)28 tf (void *arg)
29 {
30 pthread_t th;
31
32 int e = pthread_barrier_wait (&b);
33 if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
34 {
35 puts ("barrier_wait failed");
36 exit (1);
37 }
38
39 e = pthread_create (&th, NULL, tf2, NULL);
40 if (e != 0)
41 {
42 printf ("create failed: %s\n", strerror (e));
43 exit (1);
44 }
45
46 /* Terminate only this thread. */
47 return NULL;
48 }
49
50
51 static int
do_test(void)52 do_test (void)
53 {
54 pthread_t th;
55
56 if (pthread_barrier_init (&b, NULL, 2) != 0)
57 {
58 puts ("barrier_init failed");
59 exit (1);
60 }
61
62 int e = pthread_create (&th, NULL, tf, NULL);
63 if (e != 0)
64 {
65 printf ("create failed: %s\n", strerror (e));
66 exit (1);
67 }
68
69 e = pthread_barrier_wait (&b);
70 if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
71 {
72 puts ("barrier_wait failed");
73 exit (1);
74 }
75
76 delayed_exit (3);
77
78 /* Terminate only this thread. */
79 pthread_exit (NULL);
80
81 /* NOTREACHED */
82 return 1;
83 }
84