7 static pthread_barrier_t b
;
15 if (pthread_sigmask (SIG_SETMASK
, NULL
, &mask
) != 0)
17 puts ("pthread_sigmask failed");
20 if (sigismember (&mask
, SIGCANCEL
))
22 puts ("SIGCANCEL blocked in new thread");
26 /* Sync with the main thread so that we do not test anything else. */
27 int e
= pthread_barrier_wait (&b
);
28 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
30 puts ("barrier_wait failed");
36 /* Just a cancelable call. */
37 struct timespec ts
= { 10000, 0 };
48 if (pthread_create (&th2
, NULL
, tf2
, NULL
) != 0)
50 puts ("unwhand: create failed");
59 pthread_cleanup_push (unwhand
, NULL
);
61 /* Sync with the main thread so that we do not test anything else. */
62 int e
= pthread_barrier_wait (&b
);
63 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
65 puts ("barrier_wait failed");
71 /* Just a cancelable call. */
72 struct timespec ts
= { 10000, 0 };
76 pthread_cleanup_pop (0);
85 if (pthread_barrier_init (&b
, NULL
, 2) != 0)
87 puts ("barrier_init failed");
92 if (pthread_create (&th1
, NULL
, tf
, NULL
) != 0)
94 puts ("create failed");
98 int e
= pthread_barrier_wait (&b
);
99 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
101 puts ("barrier_wait failed");
105 /* Make sure tf1 enters nanosleep. */
106 struct timespec ts
= { 0, 500000000 };
107 while (nanosleep (&ts
, &ts
) != 0)
110 if (pthread_cancel (th1
) != 0)
112 puts ("1st cancel failed");
117 if (pthread_join (th1
, &res
) != 0)
119 puts ("1st join failed");
122 if (res
!= PTHREAD_CANCELED
)
124 puts ("1st thread not canceled");
128 e
= pthread_barrier_wait (&b
);
129 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
131 puts ("barrier_wait failed");
135 /* Make sure tf2 enters nanosleep. */
137 ts
.tv_nsec
= 500000000;
138 while (nanosleep (&ts
, &ts
) != 0)
141 puts ("calling pthread_cancel the second time");
142 if (pthread_cancel (th2
) != 0)
144 puts ("2nd cancel failed");
148 puts ("calling pthread_join the second time");
149 if (pthread_join (th2
, &res
) != 0)
151 puts ("2nd join failed");
154 if (res
!= PTHREAD_CANCELED
)
156 puts ("2nd thread not canceled");
160 if (pthread_barrier_destroy (&b
) != 0)
162 puts ("barrier_destroy failed");
169 #define TEST_FUNCTION do_test ()
171 #include "../test-skeleton.c"