x86_64: Fix svml_d_erfc4_core_avx2.S code formatting
[glibc.git] / sysdeps / pthread / tst-cancel10.c
blob15b7975992faafa11b0067bcd5cea914cd382bdf
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/>. */
18 #include <pthread.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
24 static void
25 cleanup (void *arg)
27 /* Just for fun. */
28 if (pthread_cancel (pthread_self ()) != 0)
30 puts ("cleanup: cancel failed");
31 exit (1);
34 printf ("cleanup for %ld\n", (long int) arg);
38 static void *
39 tf (void *arg)
41 long int n = (long int) arg;
43 pthread_cleanup_push (cleanup, arg);
45 if (pthread_setcanceltype ((n & 1) == 0
46 ? PTHREAD_CANCEL_DEFERRED
47 : PTHREAD_CANCEL_ASYNCHRONOUS, NULL) != 0)
49 puts ("setcanceltype failed");
50 exit (1);
53 if (pthread_cancel (pthread_self ()) != 0)
55 puts ("cancel failed");
56 exit (1);
59 pthread_testcancel ();
61 /* We should never come here. */
63 pthread_cleanup_pop (0);
65 return NULL;
69 static int
70 do_test (void)
72 pthread_attr_t at;
74 if (pthread_attr_init (&at) != 0)
76 puts ("attr_init failed");
77 return 1;
80 if (pthread_attr_setstacksize (&at, 1 * 1024 * 1024) != 0)
82 puts ("attr_setstacksize failed");
83 return 1;
86 #define N 20
87 int i;
88 pthread_t th[N];
90 for (i = 0; i < N; ++i)
91 if (pthread_create (&th[i], &at, tf, (void *) (long int) i) != 0)
93 puts ("create failed");
94 exit (1);
97 if (pthread_attr_destroy (&at) != 0)
99 puts ("attr_destroy failed");
100 return 1;
103 for (i = 0; i < N; ++i)
105 void *r;
106 if (pthread_join (th[i], &r) != 0)
108 puts ("join failed");
109 exit (1);
112 if (r != PTHREAD_CANCELED)
114 puts ("thread not canceled");
115 exit (1);
119 return 0;
123 #define TEST_FUNCTION do_test ()
124 #include "../test-skeleton.c"