]>
Commit | Line | Data |
---|---|---|
bfff8b1b | 1 | /* Copyright (C) 2002-2017 Free Software Foundation, Inc. |
76a50749 UD |
2 | This file is part of the GNU C Library. |
3 | Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. | |
4 | ||
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. | |
9 | ||
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. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public | |
59ba27a6 PE |
16 | License along with the GNU C Library; if not, see |
17 | <http://www.gnu.org/licenses/>. */ | |
76a50749 UD |
18 | |
19 | #include <pthread.h> | |
20 | #include <stdio.h> | |
21 | #include <unistd.h> | |
22 | ||
23 | #define N 2 | |
24 | ||
25 | ||
e0c68519 GG |
26 | static int do_test (void); |
27 | ||
28 | #define TEST_FUNCTION do_test () | |
29 | #include "../test-skeleton.c" | |
30 | ||
76a50749 UD |
31 | static int cnt0; |
32 | static void | |
33 | f0 (void *p) | |
34 | { | |
35 | ++cnt0; | |
36 | } | |
37 | ||
38 | ||
39 | static int cnt1; | |
40 | static void | |
41 | f1 (void *p) | |
42 | { | |
43 | ++cnt1; | |
44 | } | |
45 | ||
46 | ||
47 | static void (*fcts[N]) (void *) = | |
48 | { | |
49 | f0, | |
50 | f1 | |
51 | }; | |
52 | ||
53 | ||
54 | static void * | |
55 | tf (void *arg) | |
56 | { | |
57 | pthread_key_t *key = (pthread_key_t *) arg; | |
58 | ||
59 | if (pthread_setspecific (*key, (void *) -1l) != 0) | |
60 | { | |
e0c68519 | 61 | write_message ("setspecific failed\n"); |
76a50749 UD |
62 | _exit (1); |
63 | } | |
64 | ||
65 | return NULL; | |
66 | } | |
67 | ||
68 | ||
69 | int | |
70 | do_test (void) | |
71 | { | |
72 | pthread_key_t keys[N]; | |
73 | ||
74 | int i; | |
75 | for (i = 0; i < N; ++i) | |
76 | if (pthread_key_create (&keys[i], fcts[i]) != 0) | |
77 | { | |
e0c68519 | 78 | write_message ("key_create failed\n"); |
76a50749 UD |
79 | _exit (1); |
80 | } | |
81 | ||
82 | pthread_t th; | |
83 | if (pthread_create (&th, NULL, tf, &keys[1]) != 0) | |
84 | { | |
e0c68519 | 85 | write_message ("create failed\n"); |
76a50749 UD |
86 | _exit (1); |
87 | } | |
88 | ||
89 | if (pthread_join (th, NULL) != 0) | |
90 | { | |
e0c68519 | 91 | write_message ("join failed\n"); |
76a50749 UD |
92 | _exit (1); |
93 | } | |
94 | ||
95 | if (cnt0 != 0) | |
96 | { | |
e0c68519 | 97 | write_message ("cnt0 != 0\n"); |
76a50749 UD |
98 | _exit (1); |
99 | } | |
100 | ||
101 | if (cnt1 != 1) | |
102 | { | |
e0c68519 | 103 | write_message ("cnt1 != 1\n"); |
76a50749 UD |
104 | _exit (1); |
105 | } | |
106 | ||
107 | for (i = 0; i < N; ++i) | |
108 | if (pthread_key_delete (keys[i]) != 0) | |
109 | { | |
e0c68519 | 110 | write_message ("key_delete failed\n"); |
76a50749 UD |
111 | _exit (1); |
112 | } | |
113 | ||
114 | return 0; | |
115 | } |