x86_64: Fix missing wcsncat function definition without multiarch (x86-64-v4)
[glibc.git] / elf / tst-single_threaded-pthread-static.c
blob9cdc4c0ce65d68cbdfac6cfea173b03631058ba8
1 /* Test support for single-thread optimizations. With threads, static version.
2 Copyright (C) 2020-2024 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 test is a stripped-down version of
20 tst-single_threaded-pthread.c, without any loading of dynamic
21 objects. */
23 #include <stdio.h>
24 #include <support/check.h>
25 #include <support/xthread.h>
26 #include <sys/single_threaded.h>
28 /* First barrier synchronizes main thread, thread 1, thread 2. */
29 static pthread_barrier_t barrier1;
31 /* Second barrier synchronizes main thread, thread 2. */
32 static pthread_barrier_t barrier2;
34 static void *
35 threadfunc (void *closure)
37 TEST_VERIFY (!__libc_single_threaded);
39 /* Wait for the main thread and the other thread. */
40 xpthread_barrier_wait (&barrier1);
41 TEST_VERIFY (!__libc_single_threaded);
43 /* Second thread waits on second barrier, too. */
44 if (closure != NULL)
45 xpthread_barrier_wait (&barrier2);
46 TEST_VERIFY (!__libc_single_threaded);
48 return NULL;
51 static int
52 do_test (void)
54 TEST_VERIFY (__libc_single_threaded);
56 /* Two threads plus main thread. */
57 xpthread_barrier_init (&barrier1, NULL, 3);
59 /* Main thread and second thread. */
60 xpthread_barrier_init (&barrier2, NULL, 2);
62 pthread_t thr1 = xpthread_create (NULL, threadfunc, NULL);
63 TEST_VERIFY (!__libc_single_threaded);
65 pthread_t thr2 = xpthread_create (NULL, threadfunc, &thr2);
66 TEST_VERIFY (!__libc_single_threaded);
68 xpthread_barrier_wait (&barrier1);
69 TEST_VERIFY (!__libc_single_threaded);
71 /* Join first thread. This should not bring us back into
72 single-threaded mode. */
73 xpthread_join (thr1);
74 TEST_VERIFY (!__libc_single_threaded);
76 /* We may be back in single-threaded mode after joining both
77 threads, but this is not guaranteed. */
78 xpthread_barrier_wait (&barrier2);
79 xpthread_join (thr2);
80 printf ("info: __libc_single_threaded after joining all threads: %d\n",
81 __libc_single_threaded);
83 return 0;
86 #include <support/test-driver.c>