aarch64: Cleanup memset ifunc
[glibc.git] / htl / tests / test-8.c
blob2fd15b04eff902dc4efa20dcb89d79a272b8a8ff
1 /* Test pthread_once.
2 Copyright (C) 2000-2022 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/>. */
19 #define _GNU_SOURCE
21 #include <pthread.h>
22 #include <assert.h>
23 #include <error.h>
24 #include <errno.h>
26 #define THREADS 10
28 pthread_once_t inc_var_once = PTHREAD_ONCE_INIT;
29 int var;
31 void
32 inc_var (void)
34 var++;
37 void *
38 thr (void *arg)
40 int i;
42 for (i = 0; i < 500; i++)
43 pthread_once (&inc_var_once, inc_var);
45 return 0;
48 int
49 main (int argc, char **argv)
51 error_t err;
52 int i;
53 pthread_t tid[THREADS];
55 for (i = 0; i < THREADS; i++)
57 err = pthread_create (&tid[i], 0, thr, 0);
58 if (err)
59 error (1, err, "pthread_create (%d)", i);
62 assert (thr (0) == 0);
64 for (i = 0; i < THREADS; i++)
66 void *ret;
68 err = pthread_join (tid[i], &ret);
69 if (err)
70 error (1, err, "pthread_join");
72 assert (ret == 0);
75 assert (var == 1);
77 return 0;