1 /* Test Thread-Specific Data.
2 Copyright (C) 2000-2021 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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 <https://www.gnu.org/licenses/>. */
30 pthread_key_t key
[KEYS
];
38 for (i
= 0; i
< KEYS
; i
++)
40 printf ("pthread_getspecific(%d).\n", key
[i
]);
41 assert (pthread_getspecific (key
[i
]) == NULL
);
42 printf ("pthread_setspecific(%d, %d).\n", key
[i
], pthread_self ());
43 err
= pthread_setspecific (key
[i
], (void *) pthread_self ());
44 printf ("pthread_setspecific(%d, %d) => %d.\n", key
[i
], pthread_self (),
53 main (int argc
, char **argv
)
57 pthread_t tid
[THREADS
];
61 assert ((pthread_t
) val
== pthread_self ());
64 assert (pthread_getspecific ((pthread_key_t
) 0) == NULL
);
65 assert (pthread_setspecific ((pthread_key_t
) 0, (void *) 0x1) == EINVAL
);
67 for (i
= 0; i
< KEYS
; i
++)
68 err
= pthread_key_create (&key
[i
], des
);
70 for (i
= 0; i
< THREADS
; i
++)
72 err
= pthread_create (&tid
[i
], 0, thr
, 0);
74 error (1, err
, "pthread_create (%d)", i
);
77 for (i
= 0; i
< THREADS
; i
++)
81 err
= pthread_join (tid
[i
], &ret
);
83 error (1, err
, "pthread_join");