1 /* Test for exit/dlclose race (Bug 22180).
2 Copyright (C) 2017-2021 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 /* This file must be run from within a directory called "stdlib". */
21 /* This test verifies that when dlopen in one thread races against exit
22 in another thread, we don't call registered destructor twice.
32 #include <semaphore.h>
33 #include <support/check.h>
34 #include <support/xdlfcn.h>
35 #include <support/xthread.h>
37 /* Semaphore to ensure we have a happens-before between the first function
38 starting and exit being called. */
41 /* Semaphore to ensure we have a happens-before between the second function
42 starting and the first function returning. */
46 exit_thread (void *arg
)
48 /* Wait for the dlclose to start... */
50 /* Then try to run the exit sequence which should call all
51 __cxa_atexit registered functions and in parallel with
52 the executing dlclose(). */
60 /* Let dlclose thread proceed. */
72 dso
= xdlopen ("$ORIGIN/test-dlclose-exit-race-helper.so",
73 RTLD_NOW
|RTLD_GLOBAL
);
74 thread
= xpthread_create (NULL
, exit_thread
, NULL
);
77 xpthread_join (thread
);
79 FAIL_EXIT1 ("Did not terminate via exit(0) in exit_thread() as expected.");