2003-01-31 17:28:16

by Saurabh Desai

[permalink] [raw]
Subject: [PATCH]fix for thread signal delivery


#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include <signal.h>

void sigcatcher(int sig)
{
fprintf(stderr, "The sigcatcher caught signal %d\n", sig);
pthread_exit(0);
}

void *sig_thread(void *p)
{
sigset_t sigs_to_catch;

/* Unblock SIGINT */
sigemptyset(&sigs_to_catch);
sigaddset(&sigs_to_catch, SIGINT);
pthread_sigmask(SIG_UNBLOCK, &sigs_to_catch, NULL);

fprintf(stderr, "sent a SIGINT (ctrl-C) to this process(%d)\n", getpid());
sleep(60);

return (NULL);
}

extern int main(void)
{
pthread_t thread;
sigset_t sigs_to_block;
struct sigaction action;

/* Block all signals */
sigfillset(&sigs_to_block);
pthread_sigmask(SIG_BLOCK, &sigs_to_block, NULL);
/* Set a signal handler */
action.sa_handler = sigcatcher;
action.sa_flags = 0;
sigaction(SIGINT, &action, NULL);

pthread_create(&thread, NULL, sig_thread, NULL);

/* wait until thread is finished */
pthread_join(thread, NULL);

return 0;
}


Attachments:
sigfix.diff (543.00 B)
tsig.c (1.01 kB)
Download all attachments