1 /* Check if printf like functions does not disable asynchronous cancellation
4 Copyright (C) 2022-2023 Free Software Foundation, Inc.
5 This file is part of the GNU C Library.
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, see
19 <https://www.gnu.org/licenses/>. */
21 #include <support/check.h>
22 #include <support/xstdio.h>
23 #include <support/xthread.h>
24 #include <sys/syscall.h>
27 static pthread_barrier_t b
;
34 TEST_COMPARE (pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS
, NULL
), 0);
36 TEST_COMPARE (pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS
, &old
), 0);
37 TEST_COMPARE (old
, PTHREAD_CANCEL_ASYNCHRONOUS
);
39 /* Check if internal lock cleanup routines restore the cancellation type
42 TEST_COMPARE (pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS
, &old
), 0);
43 TEST_COMPARE (old
, PTHREAD_CANCEL_ASYNCHRONOUS
);
45 xpthread_barrier_wait (&b
);
47 /* Wait indefinitely for cancellation, which only works if asynchronous
48 cancellation is enabled. */
49 #if defined SYS_ppoll || defined SYS_ppoll_time64
50 # ifndef SYS_ppoll_time64
51 # define SYS_ppoll_time64 SYS_ppoll
53 syscall (SYS_ppoll_time64
, NULL
, 0, NULL
, NULL
);
64 xpthread_barrier_init (&b
, NULL
, 2);
66 pthread_t th
= xpthread_create (NULL
, tf
, NULL
);
68 xpthread_barrier_wait (&b
);
72 void *status
= xpthread_join (th
);
73 TEST_VERIFY (status
== PTHREAD_CANCELED
);
78 /* There is no need to wait full TIMEOUT if asynchronous is not working. */
80 #include <support/test-driver.c>