njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1 | #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 | |
| 9 | static void sig_usr1(int); |
| 10 | |
| 11 | static pthread_t main_thread; |
| 12 | |
| 13 | void * |
| 14 | child_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); |
| 22 | fprintf (stdout, "thread %ld sending SIGUSR1 to thread %ld\n", |
| 23 | pthread_self (), main_thread); |
| 24 | if (pthread_kill (main_thread, SIGUSR1) != 0) |
| 25 | fprintf (stderr, "error doing pthread_kill\n"); |
| 26 | // } |
| 27 | |
| 28 | return no_args; |
| 29 | } |
| 30 | |
| 31 | int |
| 32 | main(void) |
| 33 | { |
| 34 | struct sigaction sigact; |
| 35 | sigset_t newmask, oldmask; |
| 36 | pthread_t child; |
| 37 | |
| 38 | memset(&newmask, 0, sizeof newmask); |
| 39 | sigemptyset (&newmask); |
| 40 | sigaddset (&newmask, SIGUSR1); |
| 41 | |
| 42 | if (pthread_sigmask (SIG_BLOCK, &newmask, &oldmask) != 0) |
| 43 | fprintf (stderr, "SIG_BLOCK error"); |
| 44 | |
| 45 | memset (&sigact, 0, sizeof sigact); |
| 46 | sigact.sa_handler = sig_usr1; |
| 47 | if (sigaction(SIGUSR1, &sigact, NULL) != 0) |
| 48 | fprintf (stderr, "signal(SIGINT) error"); |
| 49 | |
| 50 | main_thread = pthread_self (); |
| 51 | if (pthread_create (&child, NULL, child_main, NULL) != 0) |
| 52 | fprintf (stderr, "error creating thread"); |
| 53 | |
| 54 | pthread_join (child, NULL); |
| 55 | |
| 56 | exit(0); |
| 57 | } |
| 58 | |
| 59 | static void |
| 60 | sig_usr1 (int signo) |
| 61 | { |
| 62 | fprintf (stderr, "SHOULD NOT BE HERE (SIGUSR1)!!!!\n"); |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | |