Commit | Line | Data |
---|---|---|
8cf6e61a | 1 | /* Test program for non-stop debugging. |
4c38e0a4 | 2 | Copyright 1996, 2002, 2003, 2004, 2007, 2008, 2009, 2010 |
0fb0cc75 | 3 | Free Software Foundation, Inc. |
8cf6e61a VP |
4 | |
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 3 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
19 | ||
20 | #include <stdio.h> | |
21 | #include <stdlib.h> | |
22 | #include <pthread.h> | |
23 | ||
24 | /* Under OSF 2.0 & 3.0 and HPUX 10, the second arg of pthread_create | |
25 | is prototyped to be just a "pthread_attr_t", while under Solaris it | |
26 | is a "pthread_attr_t *". Arg! */ | |
27 | ||
28 | #if defined (__osf__) || defined (__hpux__) | |
29 | #define PTHREAD_CREATE_ARG2(arg) arg | |
30 | #define PTHREAD_CREATE_NULL_ARG2 null_attr | |
31 | static pthread_attr_t null_attr; | |
32 | #else | |
33 | #define PTHREAD_CREATE_ARG2(arg) &arg | |
34 | #define PTHREAD_CREATE_NULL_ARG2 NULL | |
35 | #endif | |
36 | ||
37 | int exit_first_thread = 0; | |
38 | ||
39 | void break_at_me (int id, int i) | |
40 | { | |
41 | } | |
42 | ||
43 | void * | |
44 | worker (void *arg) | |
45 | { | |
80f73d71 | 46 | int id = *(int *)arg; |
8cf6e61a VP |
47 | int i = 0; |
48 | ||
49 | /* When gdb is running, it sets hidden breakpoints in the thread | |
50 | library. The signals caused by these hidden breakpoints can | |
51 | cause system calls such as 'sleep' to return early. Pay attention | |
52 | to the return value from 'sleep' to get the full sleep. */ | |
53 | for (;;++i) | |
54 | { | |
55 | int unslept = 1; | |
56 | while (unslept > 0) | |
57 | unslept = sleep (unslept); | |
58 | ||
59 | if (exit_first_thread && id == 0) | |
60 | return; | |
61 | ||
62 | break_at_me (id, i); | |
63 | } | |
64 | } | |
65 | ||
66 | pthread_t | |
67 | create_thread (int id) | |
68 | { | |
69 | pthread_t tid; | |
80f73d71 VP |
70 | /* This memory will be leaked, we don't care for a test. */ |
71 | int *id2 = malloc (sizeof (int)); | |
72 | *id2 = id; | |
8cf6e61a | 73 | |
80f73d71 | 74 | if (pthread_create (&tid, PTHREAD_CREATE_NULL_ARG2, worker, (void *) id2)) |
8cf6e61a VP |
75 | { |
76 | perror ("pthread_create 1"); | |
77 | exit (1); | |
78 | } | |
79 | return tid; | |
80 | } | |
81 | ||
82 | int | |
83 | main (int argc, char *argv[]) | |
84 | { | |
85 | pthread_t tid; | |
86 | create_thread (0); | |
87 | sleep (1); | |
88 | tid = create_thread (1); | |
89 | pthread_join (tid, NULL); | |
90 | ||
91 | return 0; | |
92 | } | |
93 |