LoongArch: Use "$fcsr0" instead of "$r0" in _FPU_{GET,SET}CW
[glibc.git] / sysdeps / pthread / tst-key4.c
blobc4d4725bf7cc6b6b7604da259137b416a260f8cc
1 /* Copyright (C) 2003-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 <limits.h>
19 #include <pthread.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <unistd.h>
25 #ifdef PTHREAD_KEYS_MAX
26 const int max = PTHREAD_KEYS_MAX;
27 #else
28 const int max = _POSIX_THREAD_KEYS_MAX;
29 #endif
30 static pthread_key_t *keys;
33 static void *
34 tf1 (void *arg)
36 int i;
37 for (i = 0; i < max; ++i)
38 if (pthread_setspecific (keys[i], (void *) (long int) (i + 1)) != 0)
40 puts ("setspecific failed");
41 exit (1);
44 return NULL;
48 static void *
49 tf2 (void *arg)
51 int i;
52 for (i = 0; i < max; ++i)
53 if (pthread_getspecific (keys[i]) != NULL)
55 printf ("getspecific for key %d not NULL\n", i);
56 exit (1);
59 return NULL;
63 static int
64 do_test (void)
66 keys = alloca (max * sizeof (pthread_key_t));
68 int i;
69 for (i = 0; i < max; ++i)
70 if (pthread_key_create (&keys[i], NULL) != 0)
72 puts ("key_create failed");
73 exit (1);
76 pthread_attr_t a;
78 if (pthread_attr_init (&a) != 0)
80 puts ("attr_init failed");
81 exit (1);
84 if (pthread_attr_setstacksize (&a, 1 * 1024 * 1024) != 0)
86 puts ("attr_setstacksize failed");
87 return 1;
90 for (i = 0; i < 10; ++i)
92 int j;
93 #define N 2
94 pthread_t th[N];
95 for (j = 0; j < N; ++j)
96 if (pthread_create (&th[j], NULL, tf1, NULL) != 0)
98 puts ("1st create failed");
99 exit (1);
102 for (j = 0; j < N; ++j)
103 if (pthread_join (th[j], NULL) != 0)
105 puts ("1st join failed");
106 exit (1);
109 for (j = 0; j < N; ++j)
110 if (pthread_create (&th[j], NULL, tf2, NULL) != 0)
112 puts ("2nd create failed");
113 exit (1);
116 for (j = 0; j < N; ++j)
117 if (pthread_join (th[j], NULL) != 0)
119 puts ("2nd join failed");
120 exit (1);
124 if (pthread_attr_destroy (&a) != 0)
126 puts ("attr_destroy failed");
127 exit (1);
130 return 0;
134 #define TEST_FUNCTION do_test ()
135 #include "../test-skeleton.c"