Next: Functions for Waiting According to a Specific Clock, Previous: Setting Process-wide defaults for thread attributes, Up: Non-POSIX Extensions [Contents][Index]
The GNU C Library provides a way to specify the initial signal mask of a
thread created using pthread_create
, passing a thread attribute
object configured for this purpose.
Preliminary: | MT-Safe | AS-Unsafe heap | AC-Unsafe mem | See POSIX Safety Concepts.
Change the initial signal mask specified by attr. If
sigmask is not NULL
, the initial signal mask for new
threads created with attr is set to *sigmask
. If
sigmask is NULL
, attr will no longer specify an
explicit signal mask, so that the initial signal mask of the new
thread is inherited from the thread that calls pthread_create
.
This function returns zero on success, and ENOMEM
on memory
allocation failure.
Preliminary: | MT-Safe | AS-Unsafe heap | AC-Unsafe mem | See POSIX Safety Concepts.
Retrieve the signal mask stored in attr and copy it to
*sigmask
. If the signal mask has not been set, return
the special constant PTHREAD_ATTR_NO_SIGMASK_NP
, otherwise
return zero.
Obtaining the signal mask only works if it has been previously stored
by pthread_attr_setsigmask_np
. For example, the
pthread_getattr_np
function does not obtain the current signal
mask of the specified thread, and pthread_attr_getsigmask_np
will subsequently report the signal mask as unset.
The special value returned by pthread_attr_setsigmask_np
to
indicate that no signal mask has been set for the attribute.
It is possible to create a new thread with a specific signal mask
without using these functions. On the thread that calls
pthread_create
, the required steps for the general case are:
pthread_sigmask
. This ensures that the new thread will be
created with all signals masked, so that no signals can be delivered
to the thread until the desired signal mask is set.
pthread_create
to create the new thread, passing the
desired signal mask to the thread start routine (which could be a
wrapper function for the actual thread start routine). It may be
necessary to make a copy of the desired signal mask on the heap, so
that the life-time of the copy extends to the point when the start
routine needs to access the signal mask.
The start routine for the created thread needs to locate the desired
signal mask and use pthread_sigmask
to apply it to the thread.
If the signal mask was copied to a heap allocation, the copy should be
freed.