]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.mi/pthreads.c
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.mi / pthreads.c
1 /* Pthreads test program.
2 Copyright 1996, 2002, 2003, 2004, 2007 Free Software Foundation, Inc.
3
4 Written by Keith Seitz of Red Hat.
5 Copied from gdb.threads/pthreads.c.
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
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
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.
19
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. */
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <pthread.h>
28
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! */
32
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;
37 #else
38 #define PTHREAD_CREATE_ARG2(arg) &arg
39 #define PTHREAD_CREATE_NULL_ARG2 NULL
40 #endif
41
42 void *
43 routine (void *arg)
44 {
45 /* When gdb is running, it sets hidden breakpoints in the thread
46 library. The signals caused by these hidden breakpoints can
47 cause system calls such as 'sleep' to return early. Pay attention
48 to the return value from 'sleep' to get the full sleep. */
49 int unslept = 9;
50 while (unslept > 0)
51 unslept = sleep (unslept);
52
53 printf ("hello thread\n");
54 }
55
56 /* Marker function for the testsuite */
57 void
58 done_making_threads (void)
59 {
60 /* Nothing */
61 }
62
63 void
64 create_thread (void)
65 {
66 pthread_t tid;
67
68 if (pthread_create (&tid, PTHREAD_CREATE_NULL_ARG2, routine, (void *) 0xfeedface))
69 {
70 perror ("pthread_create 1");
71 exit (1);
72 }
73 }
74
75 int
76 main (int argc, char *argv[])
77 {
78 int i;
79
80 /* Create a few threads */
81 for (i = 0; i < 5; i++)
82 create_thread ();
83 done_making_threads ();
84
85 printf ("hello\n");
86 printf ("hello\n");
87 return 0;
88 }
89