#include #include #include #include struct uc_threadqueue queue; struct my_msg { struct uc_threadmsg uc_msg; int sig; }; void *handler(void *arg) { for (;;) { struct uc_threadmsg *msg; struct my_msg *my; if (uc_thread_queue_get(&queue, NULL, &msg) != 0) { printf("uc_threadqueue_get failed\n"); return NULL; } my = (struct my_msg*)msg; printf("handler got signal %d\n", my->sig); free(my); } return NULL; } int main(int argc, char *argv[]) { pthread_t tid1,tid2; int i; sigset_t set; sigset_t oldset; sigemptyset(&set); sigaddset(&set, SIGUSR1); sigaddset(&set, SIGUSR2); sigaddset(&set, SIGHUP); if(pthread_sigmask(SIG_BLOCK, &set, &oldset) != 0) { perror("pthread_sigmask 1"); } uc_thread_queue_init(&queue, 1); if (pthread_create(&tid2, NULL, handler, NULL) != 0) { perror("pthread_create"); return 1; } for (;;) { int sig; if(sigwait(&set, &sig) != 0) { perror("sigwait"); break; } struct my_msg *msg = malloc(sizeof *msg); msg->sig = sig; uc_thread_queue_add(&queue, msg); } return 0; }