Add further tests of cosh and sinh.
[glibc.git] / nptl / tst-cancel25.c
blobed4205ec45a3fa3ee03b39060f1588339076e677
1 #include <pthreadP.h>
2 #include <signal.h>
3 #include <stdio.h>
4 #include <stdlib.h>
7 static pthread_barrier_t b;
8 static pthread_t th2;
11 static void *
12 tf2 (void *arg)
14 #ifdef SIGCANCEL
15 sigset_t mask;
16 if (pthread_sigmask (SIG_SETMASK, NULL, &mask) != 0)
18 puts ("pthread_sigmask failed");
19 exit (1);
21 if (sigismember (&mask, SIGCANCEL))
23 puts ("SIGCANCEL blocked in new thread");
24 exit (1);
26 #endif
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");
33 exit (1);
36 while (1)
38 /* Just a cancelable call. */
39 struct timespec ts = { 10000, 0 };
40 nanosleep (&ts, 0);
43 return NULL;
47 static void
48 unwhand (void *arg)
50 if (pthread_create (&th2, NULL, tf2, NULL) != 0)
52 puts ("unwhand: create failed");
53 exit (1);
58 static void *
59 tf (void *arg)
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");
68 exit (1);
71 while (1)
73 /* Just a cancelable call. */
74 struct timespec ts = { 10000, 0 };
75 nanosleep (&ts, 0);
78 pthread_cleanup_pop (0);
80 return NULL;
84 static int
85 do_test (void)
87 if (pthread_barrier_init (&b, NULL, 2) != 0)
89 puts ("barrier_init failed");
90 return 1;
93 pthread_t th1;
94 if (pthread_create (&th1, NULL, tf, NULL) != 0)
96 puts ("create failed");
97 return 1;
100 int e = pthread_barrier_wait (&b);
101 if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
103 puts ("barrier_wait failed");
104 return 1;
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");
115 return 1;
118 void *res;
119 if (pthread_join (th1, &res) != 0)
121 puts ("1st join failed");
122 return 1;
124 if (res != PTHREAD_CANCELED)
126 puts ("1st thread not canceled");
127 return 1;
130 e = pthread_barrier_wait (&b);
131 if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
133 puts ("barrier_wait failed");
134 return 1;
137 /* Make sure tf2 enters nanosleep. */
138 ts.tv_sec = 0;
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");
147 return 1;
150 puts ("calling pthread_join the second time");
151 if (pthread_join (th2, &res) != 0)
153 puts ("2nd join failed");
154 return 1;
156 if (res != PTHREAD_CANCELED)
158 puts ("2nd thread not canceled");
159 return 1;
162 if (pthread_barrier_destroy (&b) != 0)
164 puts ("barrier_destroy failed");
165 return 0;
168 return 0;
171 #define TEST_FUNCTION do_test ()
172 #define TIMEOUT 4
173 #include "../test-skeleton.c"