x86: Always include <dl-cet.h>/cet-tunables.h> for --enable-cet
[glibc.git] / nptl / tst-tsd4.c
blobf9b01ec52ec4325b418d0107babbe8878089dc4c
1 /* Copyright (C) 2003-2018 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
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 <limits.h>
20 #include <pthread.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <unistd.h>
26 static pthread_key_t key;
29 static int rounds;
32 static void
33 destr (void *arg)
35 ++rounds;
37 if (pthread_setspecific (key, (void *) 1l) != 0)
39 puts ("destr: setspecific failed");
40 exit (1);
45 static void *
46 tf (void *arg)
48 if (pthread_setspecific (key, (void *) 1l) != 0)
50 puts ("tf: setspecific failed");
51 exit (1);
54 return NULL;
58 /* This test check non-standard behavior. The standard does not
59 require that the implementation has to stop calling TSD destructors
60 when they are set over and over again. But NPTL does. */
61 static int
62 do_test (void)
64 /* Allocate two keys, both with destructors. */
65 if (pthread_key_create (&key, destr) != 0)
67 puts ("key_create failed");
68 return 1;
71 pthread_t th;
72 if (pthread_create (&th, NULL, tf, NULL) != 0)
74 puts ("create failed");
75 return 1;
78 if (pthread_join (th, NULL) != 0)
80 puts ("join failed");
81 return 1;
84 if (rounds < PTHREAD_DESTRUCTOR_ITERATIONS)
86 printf ("rounds == %d, PTHREAD_DESTRUCTOR_ITERATIONS = %d\n",
87 rounds, PTHREAD_DESTRUCTOR_ITERATIONS);
88 return 1;
91 if (pthread_getspecific (key) != NULL)
93 puts ("key data != NULL");
94 return 1;
97 return 0;
101 #define TEST_FUNCTION do_test ()
102 #include "../test-skeleton.c"