1 /* Pthreads test program.
2 Copyright 1996, 2002, 2003, 2004
3 Free Software Foundation, Inc.
5 Written by Fred Fish of Cygnus Support
6 Contributed by Cygnus Support
8 This file is part of GDB.
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
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
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.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
29 /* Under OSF 2.0 & 3.0 and HPUX 10, the second arg of pthread_create
30 is prototyped to be just a "pthread_attr_t", while under Solaris it
31 is a "pthread_attr_t *". Arg! */
33 #if defined (__osf__) || defined (__hpux__)
34 #define PTHREAD_CREATE_ARG2(arg) arg
35 #define PTHREAD_CREATE_NULL_ARG2 null_attr
36 static pthread_attr_t null_attr
;
38 #define PTHREAD_CREATE_ARG2(arg) &arg
39 #define PTHREAD_CREATE_NULL_ARG2 NULL
42 static int verbose
= 0;
48 static int from_thread1
;
49 static int from_thread2
;
52 static int full_coverage
;
54 if (verbose
) printf("common_routine (%d)\n", arg
);
68 if (from_main
&& from_thread1
&& from_thread2
)
78 if (verbose
) printf ("thread1 (%0x) ; pid = %d\n", arg
, getpid ());
79 for (i
=1; i
<= 10000000; i
++)
81 if (verbose
) printf("thread1 %d\n", pthread_self ());
95 if (verbose
) printf ("thread2 (%0x) ; pid = %d\n", arg
, getpid ());
96 for (i
=1; i
<= 10000000; i
++)
98 if (verbose
) printf("thread2 %d\n", pthread_self ());
113 if (verbose
) printf("a=%d\n", a
);
120 pthread_t tid1
, tid2
;
126 if (verbose
) printf ("pid = %d\n", getpid());
131 if (pthread_attr_init (&attr
))
133 perror ("pthread_attr_init 1");
138 #ifdef PTHREAD_SCOPE_SYSTEM
139 if (pthread_attr_setscope (&attr
, PTHREAD_SCOPE_SYSTEM
))
141 perror ("pthread_attr_setscope 1");
146 if (pthread_create (&tid1
, PTHREAD_CREATE_ARG2(attr
), thread1
, (void *) 0xfeedface))
148 perror ("pthread_create 1");
151 if (verbose
) printf ("Made thread %d\n", tid1
);
154 if (pthread_create (&tid2
, PTHREAD_CREATE_NULL_ARG2
, thread2
, (void *) 0xdeadbeef))
156 perror ("pthread_create 2");
159 if (verbose
) printf("Made thread %d\n", tid2
);
163 for (j
= 1; j
<= 10000000; j
++)
165 if (verbose
) printf("top %d\n", pthread_self ());