platform.texi: Move LAM after LAHF64_SAHF64
[glibc.git] / elf / tst-tls21.c
blobb2d94cd3a7842792e8cd142fafb47be2566cc764
1 /* Test concurrent dlopen and pthread_create: BZ 19329.
2 Copyright (C) 2021-2023 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 <http://www.gnu.org/licenses/>. */
19 #include <dlfcn.h>
20 #include <pthread.h>
21 #include <stdio.h>
22 #include <stdatomic.h>
23 #include <support/xdlfcn.h>
24 #include <support/xthread.h>
26 #define THREADS 10000
28 static atomic_int done;
30 static void *
31 start (void *a)
33 /* Load a module with many dependencies that each have TLS. */
34 xdlopen ("tst-tls21mod.so", RTLD_LAZY);
35 atomic_store_explicit (&done, 1, memory_order_release);
36 return 0;
39 static void *
40 nop (void *a)
42 return 0;
45 static int
46 do_test (void)
48 pthread_t t1, t2;
49 int i;
51 /* Load a module with lots of dependencies and TLS. */
52 t1 = xpthread_create (0, start, 0);
54 /* Concurrently create lots of threads until dlopen is observably done. */
55 for (i = 0; i < THREADS; i++)
57 if (atomic_load_explicit (&done, memory_order_acquire) != 0)
58 break;
59 t2 = xpthread_create (0, nop, 0);
60 xpthread_join (t2);
63 xpthread_join (t1);
64 printf ("threads created during dlopen: %d\n", i);
65 return 0;
68 #include <support/test-driver.c>