]>
Commit | Line | Data |
---|---|---|
0d36baa9 PA |
1 | /* This testcase is part of GDB, the GNU debugger. |
2 | ||
1d506c26 | 3 | Copyright 2021-2024 Free Software Foundation, Inc. |
0d36baa9 PA |
4 | |
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
7 | the Free Software Foundation; either version 3 of the License, or | |
8 | (at your option) any later version. | |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
17 | ||
18 | #include <stdio.h> | |
19 | #include <pthread.h> | |
20 | #include <unistd.h> | |
21 | #include <signal.h> | |
22 | #include <stdlib.h> | |
23 | ||
24 | /* Set this to non-zero from GDB to start a third worker thread. */ | |
25 | volatile int start_third_thread = 0; | |
26 | ||
27 | void * | |
28 | thread_worker_2 (void *arg) | |
29 | { | |
30 | int i; | |
31 | ||
32 | printf ("Hello from the third thread.\n"); | |
33 | fflush (stdout); | |
34 | ||
35 | for (i = 0; i < 300; ++i) | |
36 | sleep (1); | |
37 | ||
38 | return NULL; | |
39 | } | |
40 | ||
41 | void * | |
42 | thread_worker_1 (void *arg) | |
43 | { | |
44 | int i; | |
45 | pthread_t thr; | |
46 | void *val; | |
47 | ||
48 | if (start_third_thread) | |
49 | pthread_create (&thr, NULL, thread_worker_2, NULL); | |
50 | ||
51 | printf ("Hello from the first thread.\n"); | |
52 | fflush (stdout); | |
53 | ||
54 | for (i = 0; i < 300; ++i) | |
55 | sleep (1); | |
56 | ||
57 | if (start_third_thread) | |
58 | pthread_join (thr, &val); | |
59 | ||
60 | return NULL; | |
61 | } | |
62 | ||
63 | void * | |
64 | thread_idle_loop (void *arg) | |
65 | { | |
66 | int i; | |
67 | ||
68 | for (i = 0; i < 300; ++i) | |
69 | sleep (1); | |
70 | ||
71 | return NULL; | |
72 | } | |
73 | ||
74 | int | |
75 | main () | |
76 | { | |
77 | pthread_t thr, thr_idle; | |
78 | void *val; | |
79 | ||
80 | if (getenv ("MAKE_EXTRA_THREAD") != NULL) | |
81 | pthread_create (&thr_idle, NULL, thread_idle_loop, NULL); | |
82 | ||
83 | pthread_create (&thr, NULL, thread_worker_1, NULL); | |
84 | pthread_join (thr, &val); | |
85 | ||
86 | if (getenv ("MAKE_EXTRA_THREAD") != NULL) | |
87 | pthread_join (thr_idle, &val); | |
88 | ||
89 | return 0; | |
90 | } |