1 /* Copyright (C) 2003-2022 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
26 static pthread_barrier_t b
;
32 fputs ("in cleanup\n", stdout
);
39 int fd
= open ("/dev/null", O_RDWR
);
42 puts ("cannot open /dev/null");
45 FILE *fp
= fdopen (fd
, "w");
48 puts ("fdopen failed");
52 pthread_cleanup_push (cleanup
, NULL
);
54 int e
= pthread_barrier_wait (&b
);
55 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
57 puts ("barrier_wait failed");
62 /* fprintf() uses write() which is a cancallation point. */
65 pthread_cleanup_pop (0);
74 if (pthread_barrier_init (&b
, NULL
, 2) != 0)
76 puts ("barrier_init failed");
81 if (pthread_create (&th
, NULL
, tf
, NULL
) != 0)
83 puts ("create failed");
87 int e
= pthread_barrier_wait (&b
);
88 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
90 puts ("barrier_wait failed");
98 if (pthread_cancel (th
) != 0)
100 puts ("cancel failed");
104 puts ("waiting for the child");
107 if (pthread_join (th
, &r
) != 0)
109 puts ("join failed");
113 if (r
!= PTHREAD_CANCELED
)
115 puts ("thread wasn't canceled");
123 #define TEST_FUNCTION do_test ()
124 #include "../test-skeleton.c"