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");
22 if (sigismember (&mask
, SIGCANCEL
))
24 puts ("SIGCANCEL blocked in new thread");
29 /* Sync with the main thread so that we do not test anything else. */
30 int e
= pthread_barrier_wait (&b
);
31 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
33 puts ("barrier_wait failed");
39 /* Just a cancelable call. */
40 struct timespec ts
= { 10000, 0 };
51 if (pthread_create (&th2
, NULL
, tf2
, NULL
) != 0)
53 puts ("unwhand: create failed");
62 pthread_cleanup_push (unwhand
, NULL
);
64 /* Sync with the main thread so that we do not test anything else. */
65 int e
= pthread_barrier_wait (&b
);
66 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
68 puts ("barrier_wait failed");
74 /* Just a cancelable call. */
75 struct timespec ts
= { 10000, 0 };
79 pthread_cleanup_pop (0);
88 if (pthread_barrier_init (&b
, NULL
, 2) != 0)
90 puts ("barrier_init failed");
95 if (pthread_create (&th1
, NULL
, tf
, NULL
) != 0)
97 puts ("create failed");
101 int e
= pthread_barrier_wait (&b
);
102 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
104 puts ("barrier_wait failed");
108 /* Make sure tf1 enters nanosleep. */
109 struct timespec ts
= { 0, 500000000 };
110 while (nanosleep (&ts
, &ts
) != 0)
113 if (pthread_cancel (th1
) != 0)
115 puts ("1st cancel failed");
120 if (pthread_join (th1
, &res
) != 0)
122 puts ("1st join failed");
125 if (res
!= PTHREAD_CANCELED
)
127 puts ("1st thread not canceled");
131 e
= pthread_barrier_wait (&b
);
132 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
134 puts ("barrier_wait failed");
138 /* Make sure tf2 enters nanosleep. */
140 ts
.tv_nsec
= 500000000;
141 while (nanosleep (&ts
, &ts
) != 0)
144 puts ("calling pthread_cancel the second time");
145 if (pthread_cancel (th2
) != 0)
147 puts ("2nd cancel failed");
151 puts ("calling pthread_join the second time");
152 if (pthread_join (th2
, &res
) != 0)
154 puts ("2nd join failed");
157 if (res
!= PTHREAD_CANCELED
)
159 puts ("2nd thread not canceled");
163 if (pthread_barrier_destroy (&b
) != 0)
165 puts ("barrier_destroy failed");
172 #define TEST_FUNCTION do_test ()
173 #include "../test-skeleton.c"