sigthreadmask Subroutine

Purpose

Sets the signal mask of a thread.

Library

Threads Library (libpthreads.a)

Syntax

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

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

Description

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.

Parameters

Item Description
how Indicates the manner in which the set is changed. It can have one of the following values:
SIG_BLOCK
The resulting set is the union of the current set and the signal set pointed to by the set parameter.
SIG_UNBLOCK
The resulting set is the intersection of the current set and the complement of the signal set pointed to by the set parameter.
SIG_SETMASK
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:

Item Description
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.

Examples

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;
sigemptyset(newset_p);
sigaddset(newset_p, SIGINT);
return_value = sigthreadmask(SIG_SETMASK, newset_p, NULL);