[gdb/symtab] Fix gdb.base/fission-macro.exp with unix/-m32
[binutils-gdb.git] / gdb / testsuite / gdb.threads / stepi-over-clone.c
blobf188853045e0e23005b377f88f334aa75859263e
1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2021-2024 Free Software Foundation, Inc.
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.
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.
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/>. */
18 #include <stdio.h>
19 #include <pthread.h>
20 #include <unistd.h>
21 #include <signal.h>
22 #include <stdlib.h>
24 /* Set this to non-zero from GDB to start a third worker thread. */
25 volatile int start_third_thread = 0;
27 void *
28 thread_worker_2 (void *arg)
30 int i;
32 printf ("Hello from the third thread.\n");
33 fflush (stdout);
35 for (i = 0; i < 300; ++i)
36 sleep (1);
38 return NULL;
41 void *
42 thread_worker_1 (void *arg)
44 int i;
45 pthread_t thr;
46 void *val;
48 if (start_third_thread)
49 pthread_create (&thr, NULL, thread_worker_2, NULL);
51 printf ("Hello from the first thread.\n");
52 fflush (stdout);
54 for (i = 0; i < 300; ++i)
55 sleep (1);
57 if (start_third_thread)
58 pthread_join (thr, &val);
60 return NULL;
63 void *
64 thread_idle_loop (void *arg)
66 int i;
68 for (i = 0; i < 300; ++i)
69 sleep (1);
71 return NULL;
74 int
75 main ()
77 pthread_t thr, thr_idle;
78 void *val;
80 if (getenv ("MAKE_EXTRA_THREAD") != NULL)
81 pthread_create (&thr_idle, NULL, thread_idle_loop, NULL);
83 pthread_create (&thr, NULL, thread_worker_1, NULL);
84 pthread_join (thr, &val);
86 if (getenv ("MAKE_EXTRA_THREAD") != NULL)
87 pthread_join (thr_idle, &val);
89 return 0;