Remove unused localedata/th_TH.in
[glibc.git] / sysdeps / pthread / tst-cancel30.c
blobff803386be43ded13ab3c65c47e7cca6649c6029
1 /* Check if printf like functions does not disable asynchronous cancellation
2 mode (BZ#29214).
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>
25 #include <unistd.h>
27 static pthread_barrier_t b;
29 static void *
30 tf (void *arg)
32 int old;
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
40 correctly. */
41 printf ("...\n");
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
52 # endif
53 syscall (SYS_ppoll_time64, NULL, 0, NULL, NULL);
54 #else
55 for (;;);
56 #endif
58 return 0;
61 static int
62 do_test (void)
64 xpthread_barrier_init (&b, NULL, 2);
66 pthread_t th = xpthread_create (NULL, tf, NULL);
68 xpthread_barrier_wait (&b);
70 xpthread_cancel (th);
72 void *status = xpthread_join (th);
73 TEST_VERIFY (status == PTHREAD_CANCELED);
75 return 0;
78 /* There is no need to wait full TIMEOUT if asynchronous is not working. */
79 #define TIMEOUT 3
80 #include <support/test-driver.c>