* gdb.threads/sigthread.c (NSIGS): Make bigger.
[external/binutils.git] / gdb / testsuite / gdb.threads / sigthread.c
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.
6
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.  */
11
12 #include <stdio.h>
13 #include <unistd.h>
14 #include <stdlib.h>
15 #include <pthread.h>
16 #include <signal.h>
17
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
22
23 void
24 handler (int sig)
25 {
26   ;
27 }
28
29 pthread_t main_thread;
30 pthread_t child_thread, child_thread_two;
31
32 void *
33 child_two (void *arg)
34 {
35   int i;
36
37   for (i = 0; i < NSIGS; i++)
38     pthread_kill (child_thread, SIGUSR1);
39 }
40
41 void *
42 thread_function (void *arg)
43 {
44   int i;
45
46   for (i = 0; i < NSIGS; i++)
47     pthread_kill (child_thread_two, SIGUSR2);
48 }
49
50 int main()
51 {
52   int i;
53
54   signal (SIGUSR1, handler);
55   signal (SIGUSR2, handler);
56
57   main_thread = pthread_self ();
58   pthread_create (&child_thread, NULL, thread_function, NULL);
59   pthread_create (&child_thread_two, NULL, child_two, NULL);
60
61   for (i = 0; i < NSIGS; i++)
62     pthread_kill (child_thread_two, SIGUSR1);
63
64   pthread_join (child_thread, NULL);
65
66   exit (0);
67 }