1 /* Pthreads test program.
2 Copyright 1996-2024 Free Software Foundation, Inc.
4 Written by Fred Fish of Cygnus Support
5 Contributed by Cygnus Support
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
29 static int verbose
= 0;
32 common_routine (int arg
)
34 static int from_thread1
;
35 static int from_thread2
;
38 static int full_coverage
;
41 printf ("common_routine (%d)\n", arg
);
55 if (from_main
&& from_thread1
&& from_thread2
)
66 printf ("thread1 (%0lx) ; pid = %d\n", (long) arg
, getpid ());
67 for (i
= 1; i
<= 10000000; i
++)
70 printf ("thread1 %ld\n", (long) pthread_self ());
85 printf ("thread2 (%0lx) ; pid = %d\n", (long) arg
, getpid ());
86 for (i
= 1; i
<= 10000000; i
++)
89 printf ("thread2 %ld\n", (long) pthread_self ());
99 foo (int a
, int b
, int c
)
104 printf ("a=%d\n", a
);
107 /* Similar to perror, but use ERR instead of errno. */
110 print_error (const char *ctx
, int err
)
112 fprintf (stderr
, "%s: %s (%d)\n", ctx
, strerror (err
), err
);
116 main (int argc
, char **argv
)
118 pthread_t tid1
, tid2
;
126 printf ("pid = %d\n", getpid ());
130 res
= pthread_attr_init (&attr
);
133 print_error ("pthread_attr_init 1", res
);
137 #ifdef PTHREAD_SCOPE_SYSTEM
138 res
= pthread_attr_setscope (&attr
, PTHREAD_SCOPE_SYSTEM
);
139 if (res
!= 0 && res
!= ENOTSUP
)
141 print_error ("pthread_attr_setscope 1", res
);
146 res
= pthread_create (&tid1
, &attr
, thread1
, (void *) 0xfeedface);
149 print_error ("pthread_create 1", res
);
153 printf ("Made thread %ld\n", (long) tid1
);
156 res
= pthread_create (&tid2
, NULL
, thread2
, (void *) 0xdeadbeef);
159 print_error ("pthread_create 2", res
);
163 printf ("Made thread %ld\n", (long) tid2
);
167 for (j
= 1; j
<= 10000000; j
++)
170 printf ("top %ld\n", (long) pthread_self ());