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, see
17 <http://www.gnu.org/licenses/>. */
29 static pthread_barrier_t b2
;
44 int r
= pthread_barrier_wait (&b2
);
45 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
47 puts ("child thread: barrier_wait failed");
51 pthread_cleanup_push (cl
, NULL
);
53 /* This call should never return. */
54 (void) lockf (fd
, F_LOCK
, 0);
56 pthread_cleanup_pop (0);
65 char fname
[] = "/tmp/cancel16XXXXXX";
69 puts ("mkstemp failed");
74 char mem
[sizeof (pthread_barrier_t
)];
75 memset (mem
, '\0', sizeof (mem
));
76 if (TEMP_FAILURE_RETRY (pwrite (fd
, mem
, sizeof (mem
), 0)) != sizeof (mem
))
78 puts ("pwrite failed");
82 void *p
= mmap (NULL
, sizeof (mem
), PROT_READ
|PROT_WRITE
, MAP_SHARED
, fd
, 0);
88 pthread_barrier_t
*b
= (pthread_barrier_t
*) p
;
90 pthread_barrierattr_t ba
;
91 if (pthread_barrierattr_init (&ba
) != 0)
93 puts ("barrierattr_init failed");
96 if (pthread_barrierattr_setpshared (&ba
, 1) != 0)
98 puts ("barrierattr_setshared failed");
102 if (pthread_barrier_init (b
, &ba
, 2) != 0)
104 puts ("1st barrier_init failed");
107 if (pthread_barrierattr_destroy (&ba
) != 0)
109 puts ("barrier_destroy failed");
116 /* Child. Lock the file and wait. */
117 if (lockf (fd
, F_LOCK
, 0) != 0)
119 puts ("child process: lockf failed");
123 int r
= pthread_barrier_wait (b
);
124 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
126 puts ("child process: 1st barrier_wait failed");
130 /* Make sure the process dies. */
133 r
= pthread_barrier_wait (b
);
134 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
136 puts ("child process: 2nd barrier_wait failed");
144 puts ("fork failed");
148 int r
= pthread_barrier_wait (b
);
149 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
151 puts ("main: 1st barrier_wait failed");
155 if (pthread_barrier_init (&b2
, NULL
, 2) != 0)
157 puts ("2nd barrier_init failed");
162 if (pthread_create (&th
, NULL
, tf
, NULL
) != 0)
164 puts ("create failed");
168 r
= pthread_barrier_wait (&b2
);
169 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
171 puts ("main: 2nd barrier_wait failed");
178 if (pthread_cancel (th
) != 0)
180 puts ("cancel failed");
185 if (pthread_join (th
, &result
) != 0)
187 puts ("join failed");
190 if (result
!= PTHREAD_CANCELED
)
192 puts ("thread not canceled");
197 puts ("cleanup handler not called");
201 r
= pthread_barrier_wait (b
);
202 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
204 puts ("main: 3rd barrier_wait failed");
209 if (TEMP_FAILURE_RETRY (waitpid (pid
, &status
, 0)) != pid
)
211 puts ("waitpid failed");
214 if (WEXITSTATUS (status
) != 0)
216 printf ("child process exits with %d\n", WEXITSTATUS (status
));
220 if (lockf (fd
, F_LOCK
, 0) != 0)
222 puts ("main: lockf failed");
229 #define TEST_FUNCTION do_test ()
230 #include "../test-skeleton.c"