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/>. */
28 if (pthread_cancel (pthread_self ()) != 0)
30 puts ("cleanup: cancel failed");
34 printf ("cleanup for %ld\n", (long int) 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");
53 if (pthread_cancel (pthread_self ()) != 0)
55 puts ("cancel failed");
59 pthread_testcancel ();
61 /* We should never come here. */
63 pthread_cleanup_pop (0);
74 if (pthread_attr_init (&at
) != 0)
76 puts ("attr_init failed");
80 if (pthread_attr_setstacksize (&at
, 1 * 1024 * 1024) != 0)
82 puts ("attr_setstacksize failed");
90 for (i
= 0; i
< N
; ++i
)
91 if (pthread_create (&th
[i
], &at
, tf
, (void *) (long int) i
) != 0)
93 puts ("create failed");
97 if (pthread_attr_destroy (&at
) != 0)
99 puts ("attr_destroy failed");
103 for (i
= 0; i
< N
; ++i
)
106 if (pthread_join (th
[i
], &r
) != 0)
108 puts ("join failed");
112 if (r
!= PTHREAD_CANCELED
)
114 puts ("thread not canceled");
123 #define TEST_FUNCTION do_test ()
124 #include "../test-skeleton.c"