Remove obsolete test from gdb.cp/var-tag.exp
[binutils-gdb.git] / gdb / testsuite / gdb.threads / main-thread-exit-during-detach.c
blob50849d91eef4db68e31cc00d0e2253f68c576162
1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2023-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 <pthread.h>
19 #include <unistd.h>
21 /* This is set from GDB to allow the main thread to exit. */
23 volatile int dont_exit_just_yet = 1;
25 /* Somewhere to place a breakpoint. */
27 void
28 breakpt ()
30 /* Just spin. When the test is started under GDB we never enter the spin
31 loop, but when we attach, the worker thread will be spinning here. */
32 while (dont_exit_just_yet)
33 sleep (1);
36 /* Thread function, doesn't do anything but hit a breakpoint. */
38 void *
39 thread_worker (void *arg)
41 breakpt ();
42 return NULL;
45 int
46 main ()
48 pthread_t thr;
50 alarm (300);
52 /* Create a thread. */
53 pthread_create (&thr, NULL, thread_worker, NULL);
54 pthread_detach (thr);
56 /* Spin until GDB releases us. */
57 while (dont_exit_just_yet)
58 sleep (1);
60 _exit (0);