gdb.threads/multi-create-ns-info-thr.exp and native-extended-remote board
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.threads / non-stop-fair-events.c
1 /* This testcase is part of GDB, the GNU debugger.
2
3 Copyright 2014-2015 Free Software Foundation, Inc.
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 <pthread.h>
19 #include <unistd.h>
20 #include <stdlib.h>
21 #include <signal.h>
22
23 #define NUM_THREADS 10
24 const int num_threads = NUM_THREADS;
25
26 pthread_t child_thread[NUM_THREADS];
27 volatile pthread_t signal_thread;
28 volatile int got_sig;
29
30 void
31 handler (int signo)
32 {
33 got_sig = 1;
34 }
35
36 void
37 loop_broke (void)
38 {
39 }
40
41 #define INF_LOOP \
42 do \
43 { \
44 while (!got_sig) \
45 ; \
46 } \
47 while (0)
48
49 void *
50 child_function (void *arg)
51 {
52 pthread_t self = pthread_self ();
53
54 while (1)
55 {
56 INF_LOOP; /* set thread breakpoint here */
57 loop_broke ();
58 }
59 }
60
61 int
62 main (void)
63 {
64 int res;
65 int i;
66
67 alarm (60);
68
69 signal (SIGUSR1, handler);
70
71 for (i = 0; i < NUM_THREADS; i++)
72 {
73 res = pthread_create (&child_thread[i], NULL, child_function, NULL);
74 }
75
76 while (1)
77 {
78 pthread_kill (signal_thread, SIGUSR1); /* set kill breakpoint here */
79 INF_LOOP;
80 loop_broke ();
81 }
82
83 exit(EXIT_SUCCESS);
84 }
This page took 0.030266 seconds and 4 git commands to generate.