]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.threads/staticthreads.c
Automatic Copyright Year update after running gdb/copyright.py
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.threads / staticthreads.c
CommitLineData
c72b934c
AC
1/* This test program is part of GDB, The GNU debugger.
2
4a94e368 3 Copyright 2004-2022 Free Software Foundation, Inc.
c72b934c
AC
4
5 Originally written by Jeff Johnston <jjohnstn@redhat.com>,
6 contributed by Red Hat
7
8 This file is part of GDB.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
a9762ec7 12 the Free Software Foundation; either version 3 of the License, or
c72b934c 13 (at your option) any later version.
a9762ec7 14
c72b934c
AC
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
a9762ec7 19
c72b934c 20 You should have received a copy of the GNU General Public License
a9762ec7 21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c72b934c
AC
22
23#include <pthread.h>
24#include <semaphore.h>
25#include <stdio.h>
26#include <limits.h>
27#include <errno.h>
28
29sem_t semaphore;
30
5876f503
JK
31#ifdef HAVE_TLS
32__thread int tlsvar;
33#endif
34
c72b934c
AC
35void *
36thread_function (void *arg)
37{
5876f503
JK
38#ifdef HAVE_TLS
39 tlsvar = 2;
40#endif
c72b934c
AC
41 while (sem_wait (&semaphore) != 0)
42 {
43 if (errno != EINTR)
44 {
45 perror ("thread_function");
41f1ada5 46 return NULL;
c72b934c
AC
47 }
48 }
b8b91e98 49 printf ("Thread executing\n"); /* tlsvar-is-set */
c72b934c
AC
50 return NULL;
51}
52
53int
54main (int argc, char **argv)
55{
56 pthread_attr_t attr;
57
58 pthread_attr_init (&attr);
59 pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN);
60
61 if (sem_init (&semaphore, 0, 0) == -1)
62 {
63 perror ("semaphore");
64 return -1;
65 }
66
5876f503
JK
67#ifdef HAVE_TLS
68 tlsvar = 1;
69#endif
c72b934c
AC
70
71 /* Create a thread, wait for it to complete. */
72 {
73 pthread_t thread;
74 pthread_create (&thread, &attr, thread_function, NULL);
75 sem_post (&semaphore);
76 pthread_join (thread, NULL);
77 }
78
79 pthread_attr_destroy (&attr);
80 return 0;
81}