* lib/gdb.exp (gdb_compile_test): New.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.mi / pthreads.c
CommitLineData
ae7dc4d8 1/* Pthreads test program.
0fb0cc75
JB
2 Copyright 1996, 2002, 2003, 2004, 2007, 2008, 2009
3 Free Software Foundation, Inc.
ae7dc4d8
MC
4
5 Written by Keith Seitz of Red Hat.
6 Copied from gdb.threads/pthreads.c.
7 Contributed by Red Hat.
8
9 This file is part of GDB.
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
a9762ec7 13 the Free Software Foundation; either version 3 of the License, or
ae7dc4d8 14 (at your option) any later version.
a9762ec7 15
ae7dc4d8
MC
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
a9762ec7 20
ae7dc4d8 21 You should have received a copy of the GNU General Public License
a9762ec7 22 along with this program. If not, see <http://www.gnu.org/licenses/>. */
ae7dc4d8 23
d1a2f204 24#include <stdio.h>
5a2e8882 25#include <stdlib.h>
d1a2f204
KS
26#include <pthread.h>
27
28/* Under OSF 2.0 & 3.0 and HPUX 10, the second arg of pthread_create
29 is prototyped to be just a "pthread_attr_t", while under Solaris it
30 is a "pthread_attr_t *". Arg! */
31
32#if defined (__osf__) || defined (__hpux__)
33#define PTHREAD_CREATE_ARG2(arg) arg
34#define PTHREAD_CREATE_NULL_ARG2 null_attr
35static pthread_attr_t null_attr;
36#else
37#define PTHREAD_CREATE_ARG2(arg) &arg
38#define PTHREAD_CREATE_NULL_ARG2 NULL
39#endif
40
41void *
42routine (void *arg)
43{
2fe4e8d0
MC
44 /* When gdb is running, it sets hidden breakpoints in the thread
45 library. The signals caused by these hidden breakpoints can
46 cause system calls such as 'sleep' to return early. Pay attention
47 to the return value from 'sleep' to get the full sleep. */
48 int unslept = 9;
49 while (unslept > 0)
50 unslept = sleep (unslept);
51
d1a2f204
KS
52 printf ("hello thread\n");
53}
54
55/* Marker function for the testsuite */
56void
57done_making_threads (void)
58{
59 /* Nothing */
06ded8b8 60}
d1a2f204
KS
61
62void
63create_thread (void)
64{
65 pthread_t tid;
66
67 if (pthread_create (&tid, PTHREAD_CREATE_NULL_ARG2, routine, (void *) 0xfeedface))
68 {
69 perror ("pthread_create 1");
70 exit (1);
71 }
72}
73
74int
75main (int argc, char *argv[])
76{
77 int i;
78
79 /* Create a few threads */
80 for (i = 0; i < 5; i++)
81 create_thread ();
82 done_making_threads ();
83
84 printf ("hello\n");
85 printf ("hello\n");
86 return 0;
87}
88
This page took 0.666512 seconds and 4 git commands to generate.