7 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");
28 /* Sync with the main thread so that we do not test anything else. */
29 int e
= pthread_barrier_wait (&b
);
30 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
32 puts ("barrier_wait failed");
38 /* Just a cancelable call. */
39 struct timespec ts
= { 10000, 0 };
50 if (pthread_create (&th2
, NULL
, tf2
, NULL
) != 0)
52 puts ("unwhand: create failed");
61 pthread_cleanup_push (unwhand
, NULL
);
63 /* Sync with the main thread so that we do not test anything else. */
64 int e
= pthread_barrier_wait (&b
);
65 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
67 puts ("barrier_wait failed");
73 /* Just a cancelable call. */
74 struct timespec ts
= { 10000, 0 };
78 pthread_cleanup_pop (0);
87 if (pthread_barrier_init (&b
, NULL
, 2) != 0)
89 puts ("barrier_init failed");
94 if (pthread_create (&th1
, NULL
, tf
, NULL
) != 0)
96 puts ("create failed");
100 int e
= pthread_barrier_wait (&b
);
101 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
103 puts ("barrier_wait failed");
107 /* Make sure tf1 enters nanosleep. */
108 struct timespec ts
= { 0, 500000000 };
109 while (nanosleep (&ts
, &ts
) != 0)
112 if (pthread_cancel (th1
) != 0)
114 puts ("1st cancel failed");
119 if (pthread_join (th1
, &res
) != 0)
121 puts ("1st join failed");
124 if (res
!= PTHREAD_CANCELED
)
126 puts ("1st thread not canceled");
130 e
= pthread_barrier_wait (&b
);
131 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
133 puts ("barrier_wait failed");
137 /* Make sure tf2 enters nanosleep. */
139 ts
.tv_nsec
= 500000000;
140 while (nanosleep (&ts
, &ts
) != 0)
143 puts ("calling pthread_cancel the second time");
144 if (pthread_cancel (th2
) != 0)
146 puts ("2nd cancel failed");
150 puts ("calling pthread_join the second time");
151 if (pthread_join (th2
, &res
) != 0)
153 puts ("2nd join failed");
156 if (res
!= PTHREAD_CANCELED
)
158 puts ("2nd thread not canceled");
162 if (pthread_barrier_destroy (&b
) != 0)
164 puts ("barrier_destroy failed");
171 #define TEST_FUNCTION do_test ()
173 #include "../test-skeleton.c"