S390: Move utf8-utf32-z9.c to multiarch folder and use s390_libc_ifunc_expr macro.
[glibc.git] / nptl / tst-key2.c
bloba067873aa69f953d99ddd51c1e47e5d307b02947
1 /* Copyright (C) 2002-2017 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 void *
55 tf (void *arg)
57 pthread_key_t *key = (pthread_key_t *) arg;
59 if (pthread_setspecific (*key, (void *) -1l) != 0)
61 write_message ("setspecific failed\n");
62 _exit (1);
65 return NULL;
69 int
70 do_test (void)
72 pthread_key_t keys[N];
74 int i;
75 for (i = 0; i < N; ++i)
76 if (pthread_key_create (&keys[i], fcts[i]) != 0)
78 write_message ("key_create failed\n");
79 _exit (1);
82 pthread_t th;
83 if (pthread_create (&th, NULL, tf, &keys[1]) != 0)
85 write_message ("create failed\n");
86 _exit (1);
89 if (pthread_join (th, NULL) != 0)
91 write_message ("join failed\n");
92 _exit (1);
95 if (cnt0 != 0)
97 write_message ("cnt0 != 0\n");
98 _exit (1);
101 if (cnt1 != 1)
103 write_message ("cnt1 != 1\n");
104 _exit (1);
107 for (i = 0; i < N; ++i)
108 if (pthread_key_delete (keys[i]) != 0)
110 write_message ("key_delete failed\n");
111 _exit (1);
114 return 0;