1 /* Pthreads test program.
2 Copyright 1996, 2002, 2003, 2004, 2007 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/>. */
26 /* Under OSF 2.0 & 3.0 and HPUX 10, the second arg of pthread_create
27 is prototyped to be just a "pthread_attr_t", while under Solaris it
28 is a "pthread_attr_t *". Arg! */
30 #if defined (__osf__) || defined (__hpux__)
31 #define PTHREAD_CREATE_ARG2(arg) arg
32 #define PTHREAD_CREATE_NULL_ARG2 null_attr
33 static pthread_attr_t null_attr;
35 #define PTHREAD_CREATE_ARG2(arg) &arg
36 #define PTHREAD_CREATE_NULL_ARG2 NULL
39 static int verbose = 0;
45 static int from_thread1;
46 static int from_thread2;
49 static int full_coverage;
51 if (verbose) printf("common_routine (%d)\n", arg);
65 if (from_main && from_thread1 && from_thread2)
75 if (verbose) printf ("thread1 (%0x) ; pid = %d\n", arg, getpid ());
76 for (i=1; i <= 10000000; i++)
78 if (verbose) printf("thread1 %d\n", pthread_self ());
92 if (verbose) printf ("thread2 (%0x) ; pid = %d\n", arg, getpid ());
93 for (i=1; i <= 10000000; i++)
95 if (verbose) printf("thread2 %d\n", pthread_self ());
110 if (verbose) printf("a=%d\n", a);
117 pthread_t tid1, tid2;
123 if (verbose) printf ("pid = %d\n", getpid());
128 if (pthread_attr_init (&attr))
130 perror ("pthread_attr_init 1");
135 #ifdef PTHREAD_SCOPE_SYSTEM
136 if (pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM))
138 perror ("pthread_attr_setscope 1");
143 if (pthread_create (&tid1, PTHREAD_CREATE_ARG2(attr), thread1, (void *) 0xfeedface))
145 perror ("pthread_create 1");
148 if (verbose) printf ("Made thread %d\n", tid1);
151 if (pthread_create (&tid2, PTHREAD_CREATE_NULL_ARG2, thread2, (void *) 0xdeadbeef))
153 perror ("pthread_create 2");
156 if (verbose) printf("Made thread %d\n", tid2);
160 for (j = 1; j <= 10000000; j++)
162 if (verbose) printf("top %d\n", pthread_self ());