1 /* Copyright (C) 2003-2014 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
29 if (pthread_cancel (pthread_self ()) != 0)
31 puts ("cleanup: cancel failed");
35 printf ("cleanup for %ld\n", (long int) arg);
42 long int n = (long int) arg;
44 pthread_cleanup_push (cleanup, arg);
46 if (pthread_setcanceltype ((n & 1) == 0
47 ? PTHREAD_CANCEL_DEFERRED
48 : PTHREAD_CANCEL_ASYNCHRONOUS, NULL) != 0)
50 puts ("setcanceltype failed");
54 if (pthread_cancel (pthread_self ()) != 0)
56 puts ("cancel failed");
60 pthread_testcancel ();
62 /* We should never come here. */
64 pthread_cleanup_pop (0);
75 if (pthread_attr_init (&at) != 0)
77 puts ("attr_init failed");
81 if (pthread_attr_setstacksize (&at, 1 * 1024 * 1024) != 0)
83 puts ("attr_setstacksize failed");
91 for (i = 0; i < N; ++i)
92 if (pthread_create (&th[i], &at, tf, (void *) (long int) i) != 0)
94 puts ("create failed");
98 if (pthread_attr_destroy (&at) != 0)
100 puts ("attr_destroy failed");
104 for (i = 0; i < N; ++i)
107 if (pthread_join (th[i], &r) != 0)
109 puts ("join failed");
113 if (r != PTHREAD_CANCELED)
115 puts ("thread not canceled");
124 #define TEST_FUNCTION do_test ()
125 #include "../test-skeleton.c"