masking signals

I have a problem masking signals. I want a certain thread to process a
signal, so if another thread receives it, I mask it there and raise the
signal again:

void signalhandler(int number)
{
if (phtread_self() != mainthread)
{
sigset_t set;
sigaddset(&set, number);
SignalProcmask(0, pthread_self(), SIG_BLOCK, &set, 0);
kill(getpid(), number);
}
}

However, the thread I thought I blocked gets the signal again - an endless
loop.
What am I doing wrong?
Thanks
Markus

On Sun, 3 Jun 2001 15:52:13 -0400, “Markus Loffler”
<loffler@ces.clemson.edu> wrote:

I have a problem masking signals. I want a certain thread to process a
signal, so if another thread receives it, I mask it there and raise the
signal again:

void signalhandler(int number)
{
if (phtread_self() != mainthread)
{
sigset_t set;
sigaddset(&set, number);
SignalProcmask(0, pthread_self(), SIG_BLOCK, &set, 0);
kill(getpid(), number);
}
}

However, the thread I thought I blocked gets the signal again - an endless
loop.
What am I doing wrong?

“When a signal handler is invoked, the signal responsible is
automatically masked before its handler is called (…). If the
handler returns normally, the OS restores the signal mask present just
before the handler was called as an atomic operation. Changes made
using SignalProcmask() in the handler are undone.”

Besides, the signalhandler() above is perhaps presented in
a simplified form, but there lack a sigemptyset() call.

ako

Thanks
Markus

Andrzej Kocon <ako@box43.gnet.pl> wrote:

On Sun, 3 Jun 2001 15:52:13 -0400, “Markus Loffler”
loffler@ces.clemson.edu> > wrote:

I have a problem masking signals. I want a certain thread to process a
signal, so if another thread receives it, I mask it there and raise the
signal again:

void signalhandler(int number)
{
if (phtread_self() != mainthread)
{
sigset_t set;
sigaddset(&set, number);
SignalProcmask(0, pthread_self(), SIG_BLOCK, &set, 0);
kill(getpid(), number);
}
}

However, the thread I thought I blocked gets the signal again - an endless
loop.
What am I doing wrong?

“When a signal handler is invoked, the signal responsible is
automatically masked before its handler is called (…). If the
handler returns normally, the OS restores the signal mask present just
before the handler was called as an atomic operation. Changes made
using SignalProcmask() in the handler are undone.”

Besides, the signalhandler() above is perhaps presented in
a simplified form, but there lack a sigemptyset() call.

Which means that you’re probably better off doing the masking of signals
as part of thread initialization – that is, maks off all the signals
for all the threads that don’t want signals as part of the standard
init for the threads, rather than doing it only after you’ve received
a signal.

-David

QNX Training Services
dagibbs@qnx.com