x86-64: Don't use SSE resolvers for ISA level 3 or above
[glibc.git] / sysdeps / pthread / tst-key3.c
blobf6783fde52b905a2f5c57ea2d91466c59f72ad9d
1 /* Copyright (C) 2002-2024 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 <unistd.h>
22 #define N 2
25 static int do_test (void);
27 #define TEST_FUNCTION do_test ()
28 #include "../test-skeleton.c"
30 static int cnt0;
31 static void
32 f0 (void *p)
34 ++cnt0;
38 static int cnt1;
39 static void
40 f1 (void *p)
42 ++cnt1;
46 static void (*fcts[N]) (void *) =
48 f0,
53 static pthread_barrier_t b;
56 static void *
57 tf (void *arg)
59 pthread_key_t *key = (pthread_key_t *) arg;
61 if (pthread_setspecific (*key, arg) != 0)
63 write_message ("setspecific failed\n");
64 _exit (1);
67 pthread_barrier_wait (&b);
69 const struct timespec t = { .tv_sec = 1000, .tv_nsec = 0 };
70 while (1)
71 nanosleep (&t, NULL);
73 /* NOTREACHED */
74 return NULL;
78 int
79 do_test (void)
81 pthread_key_t keys[N];
83 int i;
84 for (i = 0; i < N; ++i)
85 if (pthread_key_create (&keys[i], fcts[i]) != 0)
87 write_message ("key_create failed\n");
88 _exit (1);
91 if (pthread_barrier_init (&b, NULL, 2) != 0)
93 write_message ("barrier_init failed\n");
94 _exit (1);
97 pthread_t th;
98 if (pthread_create (&th, NULL, tf, &keys[1]) != 0)
100 write_message ("create failed\n");
101 _exit (1);
104 pthread_barrier_wait (&b);
106 if (pthread_cancel (th) != 0)
108 write_message ("cancel failed\n");
109 _exit (1);
112 void *status;
113 if (pthread_join (th, &status) != 0)
115 write_message ("join failed\n");
116 _exit (1);
119 if (status != PTHREAD_CANCELED)
121 write_message ("thread not canceled\n");
122 _exit (1);
125 /* Note that the TSD destructors not necessarily have to have
126 finished by the time pthread_join returns. At least according to
127 POSIX. We implement the stronger requirement that they indeed
128 have run and therefore these tests succeed. */
129 if (cnt0 != 0)
131 write_message ("cnt0 != 0\n");
132 _exit (1);
135 if (cnt1 != 1)
137 write_message ("cnt1 != 1\n");
138 _exit (1);
141 for (i = 0; i < N; ++i)
142 if (pthread_key_delete (keys[i]) != 0)
144 write_message ("key_delete failed\n");
145 _exit (1);
148 if (pthread_barrier_destroy (&b) != 0)
150 write_message ("barrier_destroy failed\n");
151 _exit (1);
154 return 0;