1 /* Copyright (C) 2002-2017 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
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/>. */
26 static int do_test (void);
28 #define TEST_FUNCTION do_test ()
29 #include "../test-skeleton.c"
47 static void (*fcts
[N
]) (void *) =
54 static pthread_barrier_t b
;
60 pthread_key_t
*key
= (pthread_key_t
*) arg
;
62 if (pthread_setspecific (*key
, (void *) -1l) != 0)
64 write_message ("setspecific failed\n");
68 pthread_barrier_wait (&b
);
70 const struct timespec t
= { .tv_sec
= 1000, .tv_nsec
= 0 };
82 pthread_key_t keys
[N
];
85 for (i
= 0; i
< N
; ++i
)
86 if (pthread_key_create (&keys
[i
], fcts
[i
]) != 0)
88 write_message ("key_create failed\n");
92 if (pthread_barrier_init (&b
, NULL
, 2) != 0)
94 write_message ("barrier_init failed\n");
99 if (pthread_create (&th
, NULL
, tf
, &keys
[1]) != 0)
101 write_message ("create failed\n");
105 pthread_barrier_wait (&b
);
107 if (pthread_cancel (th
) != 0)
109 write_message ("cancel failed\n");
114 if (pthread_join (th
, &status
) != 0)
116 write_message ("join failed\n");
120 if (status
!= PTHREAD_CANCELED
)
122 write_message ("thread not canceled\n");
126 /* Note that the TSD destructors not necessarily have to have
127 finished by the time pthread_join returns. At least according to
128 POSIX. We implement the stronger requirement that they indeed
129 have run and therefore these tests succeed. */
132 write_message ("cnt0 != 0\n");
138 write_message ("cnt1 != 1\n");
142 for (i
= 0; i
< N
; ++i
)
143 if (pthread_key_delete (keys
[i
]) != 0)
145 write_message ("key_delete failed\n");
149 if (pthread_barrier_destroy (&b
) != 0)
151 write_message ("barrier_destroy failed\n");