5 #include <internal-signals.h>
8 static pthread_barrier_t b
;
16 if (pthread_sigmask (SIG_SETMASK
, NULL
, &mask
) != 0)
18 puts ("pthread_sigmask failed");
21 if (sigismember (&mask
, SIGCANCEL
))
23 puts ("SIGCANCEL blocked in new thread");
27 /* Sync with the main thread so that we do not test anything else. */
28 int e
= pthread_barrier_wait (&b
);
29 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
31 puts ("barrier_wait failed");
37 /* Just a cancelable call. */
38 struct timespec ts
= { 10000, 0 };
49 if (pthread_create (&th2
, NULL
, tf2
, NULL
) != 0)
51 puts ("unwhand: create failed");
60 pthread_cleanup_push (unwhand
, NULL
);
62 /* Sync with the main thread so that we do not test anything else. */
63 int e
= pthread_barrier_wait (&b
);
64 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
66 puts ("barrier_wait failed");
72 /* Just a cancelable call. */
73 struct timespec ts
= { 10000, 0 };
77 pthread_cleanup_pop (0);
86 if (pthread_barrier_init (&b
, NULL
, 2) != 0)
88 puts ("barrier_init failed");
93 if (pthread_create (&th1
, NULL
, tf
, NULL
) != 0)
95 puts ("create failed");
99 int e
= pthread_barrier_wait (&b
);
100 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
102 puts ("barrier_wait failed");
106 /* Make sure tf1 enters nanosleep. */
107 struct timespec ts
= { 0, 500000000 };
108 while (nanosleep (&ts
, &ts
) != 0)
111 if (pthread_cancel (th1
) != 0)
113 puts ("1st cancel failed");
118 if (pthread_join (th1
, &res
) != 0)
120 puts ("1st join failed");
123 if (res
!= PTHREAD_CANCELED
)
125 puts ("1st thread not canceled");
129 e
= pthread_barrier_wait (&b
);
130 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
132 puts ("barrier_wait failed");
136 /* Make sure tf2 enters nanosleep. */
138 ts
.tv_nsec
= 500000000;
139 while (nanosleep (&ts
, &ts
) != 0)
142 puts ("calling pthread_cancel the second time");
143 if (pthread_cancel (th2
) != 0)
145 puts ("2nd cancel failed");
149 puts ("calling pthread_join the second time");
150 if (pthread_join (th2
, &res
) != 0)
152 puts ("2nd join failed");
155 if (res
!= PTHREAD_CANCELED
)
157 puts ("2nd thread not canceled");
161 if (pthread_barrier_destroy (&b
) != 0)
163 puts ("barrier_destroy failed");
170 #define TEST_FUNCTION do_test ()
171 #include "../test-skeleton.c"