[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Technical Reference: Base Operating System and Extensions , Volume 2

sigthreadmask Subroutine


Sets the signal mask of a thread.


Threads Library (libpthreads.a)


#include <pthread.h>
#include <signal.h>

int sigthreadmask( how, set, old_set)
int how;
const sigset_t *set;
sigset_t *old_set;


The sigthreadmask subroutine is used to examine or change the signal mask of the calling thread. The sigprocmask subroutine must not be used in a multi-threaded process.

Typically, the sigthreadmask(SIG_BLOCK) subroutine is used to block signals during a critical section of code. The sigthreadmask(SIG_SETMASK) subroutine is then used to restore the mask to the previous value returned by the sigthreadmask(SIG_BLOCK) subroutine.

If there are any pending unblocked signals after the call to the sigthreadmask subroutine, at least one of those signals will be delivered before the sigthreadmask subroutine returns.

The sigthreadmask subroutine does not allow the SIGKILL or SIGSTOP signal to be blocked. If a program attempts to block either signal, the sigthreadmask subroutine gives no indication of the error.

Note: The pthread.h header file must be the first included file of each source file using the threads library.


how Indicates the manner in which the set is changed. It can have one of the following values:

The resulting set is the union of the current set and the signal set pointed to by the set parameter.

The resulting set is the intersection of the current set and the complement of the signal set pointed to by the set parameter.

The resulting set is the signal set pointed to by the set parameter.
set Specifies the signal set. If the value of the Set parameter is not null, it points to a set of signals to be used to change the currently blocked set. If the value of the Set parameter is null, the value of the How parameter is not significant and the process signal mask is unchanged. Thus, the call can be used to inquire about currently blocked signals.
old_set If the old_set parameter is not the null value, the signal mask in effect at the time of the call is stored in the spaced pointed to by the old_set parameter.

Return Values

Upon completion, a value of 0 is returned. If the sigthreadmask subroutine fails, the signal mask of the process is unchanged, a value of -1 is returned, and the global variable errno is set to indicate the error.

Error Codes

The sigthreadmask subroutine is unsuccessful if the following is true:

EFAULT The set or old_set pointers are not in the process address space.
EINVAL The value of the how parameter is not supported.
EPERM The calling thread does not have the privilege to change the signal's mask.


To set the signal mask to block only the SIGINT signal from delivery, enter:

#include <pthread.h>
#include <signal.h>
int return_value;
sigset_t newset;
sigset_t *newset_p;
 . . .
newset_p = &newset;
sigaddset(newset_p, SIGINT);
return_value = sigthreadmask(SIG_SETMASK, newset_p, NULL);

Implementation Specifics

This subroutine is part of Base Operating System (BOS) Runtime.

Related Information

The kill or killpg subroutine, pthread_kill subroutine, sigaction, sigvec, or signal (sigaction, sigvec, or signal Subroutine) subroutine, sigpause (sigsuspend or sigpause Subroutine) subroutine, sigpending (sigpending Subroutine) subroutine, sigwait (sigwait Subroutine) subroutine, sigsuspend (sigsuspend or sigpause Subroutine) subroutine.

Signal Management in AIX 5L Version 5.1 General Programming Concepts: Writing and Debugging Programs.

[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]