Update ChangeLog for BZ 22884 - riscv fmax/fmin
[glibc.git] / nptl / tst-key3.c
blob4611cef28f409b382f60ec5e45ad713ea5896e02
1 /* Copyright (C) 2002-2018 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/>. */
19 #include <pthread.h>
20 #include <stdio.h>
21 #include <unistd.h>
23 #define N 2
26 static int do_test (void);
28 #define TEST_FUNCTION do_test ()
29 #include "../test-skeleton.c"
31 static int cnt0;
32 static void
33 f0 (void *p)
35 ++cnt0;
39 static int cnt1;
40 static void
41 f1 (void *p)
43 ++cnt1;
47 static void (*fcts[N]) (void *) =
49 f0,
54 static pthread_barrier_t b;
57 static void *
58 tf (void *arg)
60 pthread_key_t *key = (pthread_key_t *) arg;
62 if (pthread_setspecific (*key, (void *) -1l) != 0)
64 write_message ("setspecific failed\n");
65 _exit (1);
68 pthread_barrier_wait (&b);
70 const struct timespec t = { .tv_sec = 1000, .tv_nsec = 0 };
71 while (1)
72 nanosleep (&t, NULL);
74 /* NOTREACHED */
75 return NULL;
79 int
80 do_test (void)
82 pthread_key_t keys[N];
84 int i;
85 for (i = 0; i < N; ++i)
86 if (pthread_key_create (&keys[i], fcts[i]) != 0)
88 write_message ("key_create failed\n");
89 _exit (1);
92 if (pthread_barrier_init (&b, NULL, 2) != 0)
94 write_message ("barrier_init failed\n");
95 _exit (1);
98 pthread_t th;
99 if (pthread_create (&th, NULL, tf, &keys[1]) != 0)
101 write_message ("create failed\n");
102 _exit (1);
105 pthread_barrier_wait (&b);
107 if (pthread_cancel (th) != 0)
109 write_message ("cancel failed\n");
110 _exit (1);
113 void *status;
114 if (pthread_join (th, &status) != 0)
116 write_message ("join failed\n");
117 _exit (1);
120 if (status != PTHREAD_CANCELED)
122 write_message ("thread not canceled\n");
123 _exit (1);
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. */
130 if (cnt0 != 0)
132 write_message ("cnt0 != 0\n");
133 _exit (1);
136 if (cnt1 != 1)
138 write_message ("cnt1 != 1\n");
139 _exit (1);
142 for (i = 0; i < N; ++i)
143 if (pthread_key_delete (keys[i]) != 0)
145 write_message ("key_delete failed\n");
146 _exit (1);
149 if (pthread_barrier_destroy (&b) != 0)
151 write_message ("barrier_destroy failed\n");
152 _exit (1);
155 return 0;