New command queue-signal.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.threads / queue-signal.c
1 /* This testcase is part of GDB, the GNU debugger.
2
3 Copyright 2014 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 <signal.h>
20 #include <stdlib.h>
21 #include <unistd.h>
22
23 /* Used to individually advance each thread to the desired stopping point. */
24 int ready;
25
26 sig_atomic_t sigusr1_received;
27 sig_atomic_t sigusr2_received;
28 sig_atomic_t sigabrt_received;
29
30 static void
31 sigusr1_handler (int sig)
32 {
33 sigusr1_received = 1;
34 }
35
36 static void
37 sigusr2_handler (int sig)
38 {
39 sigusr2_received = 1;
40 }
41
42 static void
43 sigabrt_handler (int sig)
44 {
45 sigabrt_received = 1;
46 }
47
48 static void *
49 sigusr1_thread_function (void *unused)
50 {
51 while (!ready)
52 usleep (100);
53 pthread_kill (pthread_self (), SIGUSR1);
54 }
55
56 static void *
57 sigusr2_thread_function (void *unused)
58 {
59 while (!ready)
60 usleep (100);
61 /* pthread_kill (pthread_self (), SIGUSR2); - manually injected by gdb */
62 }
63
64 static void
65 all_threads_running (void)
66 {
67 while (!ready)
68 usleep (100);
69 }
70
71 static void
72 all_threads_done (void)
73 {
74 }
75
76 int
77 main ()
78 {
79 pthread_t sigusr1_thread, sigusr2_thread;
80
81 /* Protect against running forever. */
82 alarm (60);
83
84 signal (SIGUSR1, sigusr1_handler);
85 signal (SIGUSR2, sigusr2_handler);
86 signal (SIGABRT, sigabrt_handler);
87
88 /* Don't let any thread advance past initialization. */
89 ready = 0;
90
91 pthread_create (&sigusr1_thread, NULL, sigusr1_thread_function, NULL);
92 pthread_create (&sigusr2_thread, NULL, sigusr2_thread_function, NULL);
93 all_threads_running ();
94
95 pthread_kill (pthread_self (), SIGABRT);
96
97 pthread_join (sigusr1_thread, NULL);
98 pthread_join (sigusr2_thread, NULL);
99 all_threads_done ();
100
101 return 0;
102 }
This page took 0.031403 seconds and 4 git commands to generate.