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