]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/pthread/tst-key4.c
1 /* Copyright (C) 2003-2021 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/>. */
25 #ifdef PTHREAD_KEYS_MAX
26 const int max
= PTHREAD_KEYS_MAX
;
28 const int max
= _POSIX_THREAD_KEYS_MAX
;
30 static pthread_key_t
*keys
;
37 for (i
= 0; i
< max
; ++i
)
38 if (pthread_setspecific (keys
[i
], (void *) (long int) (i
+ 1)) != 0)
40 puts ("setspecific failed");
52 for (i
= 0; i
< max
; ++i
)
53 if (pthread_getspecific (keys
[i
]) != NULL
)
55 printf ("getspecific for key %d not NULL\n", i
);
66 keys
= alloca (max
* sizeof (pthread_key_t
));
69 for (i
= 0; i
< max
; ++i
)
70 if (pthread_key_create (&keys
[i
], NULL
) != 0)
72 puts ("key_create failed");
78 if (pthread_attr_init (&a
) != 0)
80 puts ("attr_init failed");
84 if (pthread_attr_setstacksize (&a
, 1 * 1024 * 1024) != 0)
86 puts ("attr_setstacksize failed");
90 for (i
= 0; i
< 10; ++i
)
95 for (j
= 0; j
< N
; ++j
)
96 if (pthread_create (&th
[j
], NULL
, tf1
, NULL
) != 0)
98 puts ("1st create failed");
102 for (j
= 0; j
< N
; ++j
)
103 if (pthread_join (th
[j
], NULL
) != 0)
105 puts ("1st join failed");
109 for (j
= 0; j
< N
; ++j
)
110 if (pthread_create (&th
[j
], NULL
, tf2
, NULL
) != 0)
112 puts ("2nd create failed");
116 for (j
= 0; j
< N
; ++j
)
117 if (pthread_join (th
[j
], NULL
) != 0)
119 puts ("2nd join failed");
124 if (pthread_attr_destroy (&a
) != 0)
126 puts ("attr_destroy failed");
134 #define TEST_FUNCTION do_test ()
135 #include "../test-skeleton.c"