Remove obsolete test from gdb.cp/var-tag.exp
[binutils-gdb.git] / gdb / testsuite / gdb.threads / attach-slow-waitpid.c
blob9cb9047d630856c0a538b541ca7093b0d16b02da
1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2018-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 <stdio.h>
20 #include <stdlib.h>
21 #include <assert.h>
22 #define NUM_THREADS 4
24 /* Crude spin lock. Threads all spin until this is set to 0. */
25 int go = 1;
27 /* Thread function, just spin until GO is set to 0. */
28 void *
29 perform_work (void *argument)
31 /* Cast to volatile to ensure that ARGUMENT is loaded each time around
32 the loop. */
33 while (*((volatile int*) argument))
35 /* Nothing. */
37 return NULL;
40 /* The spin loop for the main thread. */
41 void
42 function (void)
44 (void) perform_work (&go);
45 printf ("Finished from function\n");
48 /* Main program, create some threads which all spin waiting for GO to be
49 set to 0. */
50 int
51 main (void)
53 pthread_t threads[NUM_THREADS];
54 int result_code;
55 unsigned index;
57 /* Create some threads. */
58 for (index = 0; index < NUM_THREADS; ++index)
60 printf ("In main: creating thread %d\n", index);
61 result_code = pthread_create (&threads[index], NULL, perform_work, &go);
62 assert (!result_code);
65 function ();
67 /* Wait for each thread to complete. */
68 for (index = 0; index < NUM_THREADS; ++index)
70 /* Block until thread INDEX completes. */
71 result_code = pthread_join (threads[index], NULL);
72 assert (!result_code);
73 printf ("In main: thread %d has completed\n", index);
75 printf ("In main: All threads completed successfully\n");
76 return 0;