]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.mi/pthreads.c
daily update
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.mi / pthreads.c
CommitLineData
ae7dc4d8 1/* Pthreads test program.
9b254dd1 2 Copyright 1996, 2002, 2003, 2004, 2007, 2008 Free Software Foundation, Inc.
ae7dc4d8
MC
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
a9762ec7 12 the Free Software Foundation; either version 3 of the License, or
ae7dc4d8 13 (at your option) any later version.
a9762ec7 14
ae7dc4d8
MC
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
ae7dc4d8 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/>. */
ae7dc4d8 22
d1a2f204 23#include <stdio.h>
5a2e8882 24#include <stdlib.h>
d1a2f204
KS
25#include <pthread.h>
26
27/* Under OSF 2.0 & 3.0 and HPUX 10, the second arg of pthread_create
28 is prototyped to be just a "pthread_attr_t", while under Solaris it
29 is a "pthread_attr_t *". Arg! */
30
31#if defined (__osf__) || defined (__hpux__)
32#define PTHREAD_CREATE_ARG2(arg) arg
33#define PTHREAD_CREATE_NULL_ARG2 null_attr
34static pthread_attr_t null_attr;
35#else
36#define PTHREAD_CREATE_ARG2(arg) &arg
37#define PTHREAD_CREATE_NULL_ARG2 NULL
38#endif
39
40void *
41routine (void *arg)
42{
2fe4e8d0
MC
43 /* When gdb is running, it sets hidden breakpoints in the thread
44 library. The signals caused by these hidden breakpoints can
45 cause system calls such as 'sleep' to return early. Pay attention
46 to the return value from 'sleep' to get the full sleep. */
47 int unslept = 9;
48 while (unslept > 0)
49 unslept = sleep (unslept);
50
d1a2f204
KS
51 printf ("hello thread\n");
52}
53
54/* Marker function for the testsuite */
55void
56done_making_threads (void)
57{
58 /* Nothing */
06ded8b8 59}
d1a2f204
KS
60
61void
62create_thread (void)
63{
64 pthread_t tid;
65
66 if (pthread_create (&tid, PTHREAD_CREATE_NULL_ARG2, routine, (void *) 0xfeedface))
67 {
68 perror ("pthread_create 1");
69 exit (1);
70 }
71}
72
73int
74main (int argc, char *argv[])
75{
76 int i;
77
78 /* Create a few threads */
79 for (i = 0; i < 5; i++)
80 create_thread ();
81 done_making_threads ();
82
83 printf ("hello\n");
84 printf ("hello\n");
85 return 0;
86}
87