Update
[gdb.git] / gdb / testsuite / gdb.threads / sigthread.c
blobb5233bc9bc819d7a30d33fa241b60899611316bd
1 /* Test case for C-c sent to threads with pending signals. Before I
2 even get there, creating a thread and sending it a signal before it
3 has a chance to run leads to an internal error in GDB. We need to
4 record that there's a pending SIGSTOP, so that we'll ignore it
5 later, and pass the current signal back to the thread.
7 The fork/vfork case has similar trouble but that's even harder
8 to get around. We may need to send a SIGCONT to cancel out the
9 SIGSTOP. Different kernels may do different things if the thread
10 is stopped by ptrace and sent a SIGSTOP. */
12 #include <stdio.h>
13 #include <unistd.h>
14 #include <stdlib.h>
15 #include <pthread.h>
16 #include <signal.h>
18 /* Loop long enough for GDB to send a few signals of its own, but
19 don't hang around eating CPU forever if something goes wrong during
20 testing. */
21 #define NSIGS 10000000
23 pthread_barrier_t barrier;
25 void
26 handler (int sig)
31 pthread_t main_thread;
32 pthread_t child_thread, child_thread_two;
34 void *
35 child_two (void *arg)
37 int i;
39 pthread_barrier_wait (&barrier);
41 for (i = 0; i < NSIGS; i++)
42 pthread_kill (child_thread, SIGUSR1);
45 void *
46 thread_function (void *arg)
48 int i;
50 pthread_barrier_wait (&barrier);
52 for (i = 0; i < NSIGS; i++)
53 pthread_kill (child_thread_two, SIGUSR2);
56 int main()
58 int i;
60 signal (SIGUSR1, handler);
61 signal (SIGUSR2, handler);
63 pthread_barrier_init (&barrier, NULL, 3);
65 main_thread = pthread_self ();
66 pthread_create (&child_thread, NULL, thread_function, NULL);
67 pthread_create (&child_thread_two, NULL, child_two, NULL);
69 pthread_barrier_wait (&barrier);
71 for (i = 0; i < NSIGS; i++)
72 pthread_kill (child_thread_two, SIGUSR1);
74 pthread_join (child_thread, NULL);
76 exit (0);