* sysdeps/unix/sysv/linux/i386/vfork.S (__vfork): Record return
[glibc.git] / nptl / tst-cancel25.c
blob00b99ad553f679388c695d7fb9e382a19362c503
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 sigset_t mask;
15 if (pthread_sigmask (SIG_SETMASK, NULL, &mask) != 0)
17 puts ("pthread_sigmask failed");
18 exit (1);
20 if (sigismember (&mask, SIGCANCEL))
22 puts ("SIGCANCEL blocked in new thread");
23 exit (1);
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");
31 exit (1);
34 while (1)
36 /* Just a cancelable call. */
37 struct timespec ts = { 10000, 0 };
38 nanosleep (&ts, 0);
41 return NULL;
45 static void
46 unwhand (void *arg)
48 if (pthread_create (&th2, NULL, tf2, NULL) != 0)
50 puts ("unwhand: create failed");
51 exit (1);
56 static void *
57 tf (void *arg)
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");
66 exit (1);
69 while (1)
71 /* Just a cancelable call. */
72 struct timespec ts = { 10000, 0 };
73 nanosleep (&ts, 0);
76 pthread_cleanup_pop (0);
78 return NULL;
82 static int
83 do_test (void)
85 if (pthread_barrier_init (&b, NULL, 2) != 0)
87 puts ("barrier_init failed");
88 return 1;
91 pthread_t th1;
92 if (pthread_create (&th1, NULL, tf, NULL) != 0)
94 puts ("create failed");
95 return 1;
98 int e = pthread_barrier_wait (&b);
99 if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
101 puts ("barrier_wait failed");
102 return 1;
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");
113 return 1;
116 void *res;
117 if (pthread_join (th1, &res) != 0)
119 puts ("1st join failed");
120 return 1;
122 if (res != PTHREAD_CANCELED)
124 puts ("1st thread not canceled");
125 return 1;
128 e = pthread_barrier_wait (&b);
129 if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
131 puts ("barrier_wait failed");
132 return 1;
135 /* Make sure tf2 enters nanosleep. */
136 ts.tv_sec = 0;
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");
145 return 1;
148 puts ("calling pthread_join the second time");
149 if (pthread_join (th2, &res) != 0)
151 puts ("2nd join failed");
152 return 1;
154 if (res != PTHREAD_CANCELED)
156 puts ("2nd thread not canceled");
157 return 1;
160 if (pthread_barrier_destroy (&b) != 0)
162 puts ("barrier_destroy failed");
163 return 0;
166 return 0;
169 #define TEST_FUNCTION do_test ()
170 #define TIMEOUT 4
171 #include "../test-skeleton.c"