"pthread_setcancelstate" and "sigwaitinfo&quo

Hi all,

I have a problem with usage of “sigwaitinfo”.
/* setup waiting for a signal:*/
siginfo_t info;
sigset_t set;

sigdelset(&set, SIGINT);
sigdelset(&set, SIGHUP);
sigdelset(&set, SIGABRT);
sigdelset(&set, SIGTERM);
sigprocmask(SIG_BLOCK, &set, NULL);
sigaddset(&set, SIGINT);
sigaddset(&set, SIGHUP);
sigaddset(&set, SIGABRT);
sigaddset(&set, SIGTERM);

/* should block/wait here */
while(sigwaitinfo(&set, &info) == -1);
printf(“Got signal\n”);

The code above works perfectly,
however, when I start another thread and inside that thread do :

int state;
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &state);
pthread_setcancelstate(state, NULL);

then I do not have a printf anymore.

Do you know what the problem can be?



This is just a guess since I’ve never used these features…

Signals are not delivered to every thread in a process. Instead they are just delivered to one thread (I assume the currently running thread).

So once you started the 2nd thread it’s entirely possible the signals are never getting to the other thread and thus you are never seeing your printf.