/* $OpenBSD: pthread_kill.c,v 1.4 2003/07/31 21:48:05 deraadt Exp $ */ /* PUBLIC DOMAIN Oct 2002 */ /* * Verify that pthread_kill does the right thing, i.e. the signal * is delivered to the correct thread and proper signal processing * is performed. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void act_handler (int signal, siginfo_t * siginfo, void *context) { struct sigaction sa; char *str; sigaction (SIGUSR1, NULL, &sa); if (sa.sa_handler != SIG_DFL) abort (); if (siginfo == NULL) abort (); asprintf (&str, "act_handler: signal %d, siginfo %p, context %p\n", signal, siginfo, context); write (STDOUT_FILENO, str, (size_t)strlen(str)); free (str); } static void * run_thread1 (void *arg) { printf ("Starting THREAD1\n"); while (1) { sleep(4); printf ("THREAD1 is going back to sleep\n"); } } static void * run_thread2 (void *arg) { printf ("Starting THREAD2\n"); while (1) { sleep(4); printf ("THREAD2 is going back to sleep\n"); } } int main (int argc, char **argv) { int i; pthread_t thread1; pthread_t thread2; struct sigaction act; act.sa_sigaction = act_handler; sigemptyset (&act.sa_mask); act.sa_flags = SA_SIGINFO | SA_RESETHAND | SA_NODEFER; sigaction (SIGUSR1, &act, NULL); pthread_create (&thread1, NULL, run_thread1, NULL); pthread_create (&thread2, NULL, run_thread2, NULL); sleep (1); while (1) { sleep(4); printf ("Main thread is going back to sleep\n"); } }