I'm attempting to move a signal handler to be a thread (so I can use mutex's). I found a few pages such as this which describe what I should be doing, however when I try, the signal handler never fires.
The following is my handler:
{ 
    int status;
    // Block current thread from trapping signal:
    sigset_t sigSet;
    sigemptyset(&sigSet);
    sigaddset(&sigSet, SIGSEGV);
    status = pthread_sigmask( SIG_BLOCK, &sigSet, NULL);
    dbgassert(status == 0);
    // create thread to capture signal
    status = pthread_create(&signalThread, NULL, signalThreadFn, NULL);
    dbgassert(status == 0);
    sleep(1);
    debugf("about to die");
    // generate segv:
    rt = posix_memalign((void **)&pool, getpagesize(), getpagesize());
    dbgassert(rt==0);
    mprotect(pool, getpagesize(), PROT_READ);
    pool[0]=10;
    debugf("resurected!!!");
} 
static void *
signalThreadFn(void *parm) {
    sigset_t         sigSet;
    int              sig;
    siginfo_t        sigInfo = {};
    debugf("Starting signal thread");
    sigemptyset(&sigSet);
    sigaddset(&sigSet, SIGSEGV);
    while( 1 ) {
        debugf("waiting for SIGSEGV...");
        sig=sigwaitinfo(&sigSet,&sigInfo);
        debugf("Got signal %d",sig);
        ...
    }
}
but the thread never captures the signal. I get on output:
DEBUG [signalThreadFn.841]: waiting for SIGSEGV...
DEBUG [constructor.240]: about to die
Segmentation fault (core dumped)
I'm not sure why the signal handler is not catching the signal. From what I understand, the child thread should inherit the mask from its parent, and because SIGSEGV was disabled, neither should catch the signal until the thread does its sigwaitinfo -- why isn't the child catching the signal?