blob: 58e376db6d710ff60bb418f63c6cd4a3e65274b8 [file] [log] [blame]
njn25e49d8e72002-09-23 09:36:25 +00001#include <stdlib.h>
2#include <string.h>
3#include <unistd.h>
4#include <errno.h>
5#include <stdio.h>
6#include <signal.h>
7#include <pthread.h>
8
9static void sig_usr1(int);
10
11static pthread_t main_thread;
12
13void *
14child_main(void *no_args)
15{
16// int i;
17
18// Only do it once, to shorten test --njn
19// for (i = 0; i < 5; ++i)
20// {
21 sleep (1);
sewardjb5f6f512005-03-10 23:59:00 +000022 fprintf (stdout, "thread CHILD sending SIGUSR1 to thread MAIN\n");
njn25e49d8e72002-09-23 09:36:25 +000023 if (pthread_kill (main_thread, SIGUSR1) != 0)
24 fprintf (stderr, "error doing pthread_kill\n");
25// }
26
27 return no_args;
28}
29
30int
31main(void)
32{
33 struct sigaction sigact;
34 sigset_t newmask, oldmask;
35 pthread_t child;
36
37 memset(&newmask, 0, sizeof newmask);
38 sigemptyset (&newmask);
39 sigaddset (&newmask, SIGUSR1);
40
41 if (pthread_sigmask (SIG_BLOCK, &newmask, &oldmask) != 0)
42 fprintf (stderr, "SIG_BLOCK error");
43
44 memset (&sigact, 0, sizeof sigact);
45 sigact.sa_handler = sig_usr1;
46 if (sigaction(SIGUSR1, &sigact, NULL) != 0)
47 fprintf (stderr, "signal(SIGINT) error");
48
49 main_thread = pthread_self ();
50 if (pthread_create (&child, NULL, child_main, NULL) != 0)
51 fprintf (stderr, "error creating thread");
52
53 pthread_join (child, NULL);
54
55 exit(0);
56}
57
58static void
59sig_usr1 (int signo)
60{
61 fprintf (stderr, "SHOULD NOT BE HERE (SIGUSR1)!!!!\n");
62 return;
63}
64
65