sigaddset()

The following routine is used at thread init time. The problem is the second
sigaddset() overwrote
the first sigaddset(). Anyone know why this is happening?

static void * thread_init_func(void * arg)
{
thread_params * p_params=(thread_params *) arg;
void * rc=NULL;

if (p_params)
{
sigset_t set;

sigemptyset( &set );
sigaddset( &set, SIGUSR1 );
pthread_sigmask( SIG_UNBLOCK, &set, NULL );

sigaddset( &set, SIGALRM);
pthread_sigmask( SIG_BLOCK, &set, NULL );

rc=p_params->thread_func(p_params->arg);
free(p_params);
}
return rc;
}

Beth <id@net.com> wrote:

The following routine is used at thread init time. The problem is the second
sigaddset() overwrote
the first sigaddset(). Anyone know why this is happening?

sigset_t is a local.


static void * thread_init_func(void * arg)
{
thread_params * p_params=(thread_params *) arg;
void * rc=NULL;

if (p_params)
{
sigset_t set;

sigemptyset( &set );
sigaddset( &set, SIGUSR1 );

Sets one bit. Doesn’t change the contents of set.


pthread_sigmask( SIG_UNBLOCK, &set, NULL );

Unmasks SIGUSR1.

sigaddset( &set, SIGALRM);

Sets another bit, now bits for SIGUSR1 and SIGALRM are set in set.


pthread_sigmask( SIG_BLOCK, &set, NULL );

Masks SIGUSR1 and SIGALRM.

You probably want:

sigemptyset( &set );
sigaddset( &set, SIGALRM);
pthread_sigmask( SIG_BLOCK, &set, NULL );

So that you clear the SIGUSR1 bit that was previously set, before
adding SIGALRM to the bitfield.

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

David Gibbs <dagibbs@qnx.com> wrote:

Beth <> id@net.com> > wrote:
The following routine is used at thread init time. The problem is the second
sigaddset() overwrote
the first sigaddset(). Anyone know why this is happening?

sigset_t is a local.

if (p_params)
{
sigset_t set;

sigemptyset( &set );
sigaddset( &set, SIGUSR1 );

Sets one bit. Doesn’t change the contents of set.

That should have been:

“Sets one bit. Doesn’t change the other contents of set.”


pthread_sigmask( SIG_UNBLOCK, &set, NULL );

Unmasks SIGUSR1.

sigaddset( &set, SIGALRM);

Sets another bit, now bits for SIGUSR1 and SIGALRM are set in set.



pthread_sigmask( SIG_BLOCK, &set, NULL );

Masks SIGUSR1 and SIGALRM.

You probably want:

sigemptyset( &set );
sigaddset( &set, SIGALRM);
pthread_sigmask( SIG_BLOCK, &set, NULL );

So that you clear the SIGUSR1 bit that was previously set, before
adding SIGALRM to the bitfield.

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.


QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.