1 /* Copyright (C) 2003 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
30 static pthread_barrier_t b2;
45 int r = pthread_barrier_wait (&b2);
46 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
48 puts ("child thread: barrier_wait failed");
52 pthread_cleanup_push (cl, NULL);
54 /* This call should never return. */
55 (void) lockf (fd, F_LOCK, 0);
57 pthread_cleanup_pop (0);
66 char fname[] = "/tmp/cancel16XXXXXX";
70 puts ("mkstemp failed");
75 char mem[sizeof (pthread_barrier_t)];
76 memset (mem, '\0', sizeof (mem));
77 if (TEMP_FAILURE_RETRY (pwrite (fd, mem, sizeof (mem), 0)) != sizeof (mem))
79 puts ("pwrite failed");
83 void *p = mmap (NULL, sizeof (mem), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
89 pthread_barrier_t *b = (pthread_barrier_t *) p;
91 pthread_barrierattr_t ba;
92 if (pthread_barrierattr_init (&ba) != 0)
94 puts ("barrierattr_init failed");
97 if (pthread_barrierattr_setpshared (&ba, 1) != 0)
99 puts ("barrierattr_setshared failed");
103 if (pthread_barrier_init (b, &ba, 2) != 0)
105 puts ("1st barrier_init failed");
108 if (pthread_barrierattr_destroy (&ba) != 0)
110 puts ("barrier_destroy failed");
117 /* Child. Lock the file and wait. */
118 if (lockf (fd, F_LOCK, 0) != 0)
120 puts ("child process: lockf failed");
124 int r = pthread_barrier_wait (b);
125 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
127 puts ("child process: 1st barrier_wait failed");
131 /* Make sure the process dies. */
134 r = pthread_barrier_wait (b);
135 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
137 puts ("child process: 2nd barrier_wait failed");
145 puts ("fork failed");
149 int r = pthread_barrier_wait (b);
150 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
152 puts ("main: 1st barrier_wait failed");
156 if (pthread_barrier_init (&b2, NULL, 2) != 0)
158 puts ("2nd barrier_init failed");
163 if (pthread_create (&th, NULL, tf, NULL) != 0)
165 puts ("create failed");
169 r = pthread_barrier_wait (&b2);
170 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
172 puts ("main: 2nd barrier_wait failed");
179 if (pthread_cancel (th) != 0)
181 puts ("cancel failed");
186 if (pthread_join (th, &result) != 0)
188 puts ("join failed");
191 if (result != PTHREAD_CANCELED)
193 puts ("thread not canceled");
198 puts ("cleanup handler not called");
202 r = pthread_barrier_wait (b);
203 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
205 puts ("main: 3rd barrier_wait failed");
210 if (TEMP_FAILURE_RETRY (waitpid (pid, &status, 0)) != pid)
212 puts ("waitpid failed");
215 if (WEXITSTATUS (status) != 0)
217 printf ("child process exits with %d\n", WEXITSTATUS (status));
221 if (lockf (fd, F_LOCK, 0) != 0)
223 puts ("main: lockf failed");
230 #define TEST_FUNCTION do_test ()
231 #include "../test-skeleton.c"