# sigwait

## PROLOG



           This manual page is part of the POSIX Programmer's Manual.  The
           Linux implementation of this interface may differ (consult the
           corresponding Linux manual page for details of Linux behavior), or
           the interface may not be implemented on Linux.
    


## NAME



           sigwait — wait for queued signals
    


## SYNOPSIS



           #include <signal.h>
    
           int sigwait(const sigset_t *restrict _set_ , int *restrict _sig_);
    


## DESCRIPTION



           The _sigwait_() function shall select a pending signal from _set_ ,
           atomically clear it from the system's set of pending signals, and
           return that signal number in the location referenced by _sig_.  If
           prior to the call to _sigwait_() there are multiple pending
           instances of a single signal number, it is implementation-defined
           whether upon successful return there are any remaining pending
           signals for that signal number.  If the implementation supports
           queued signals and there are multiple signals queued for the
           signal number selected, the first such queued signal shall cause a
           return from _sigwait_() and the remainder shall remain queued. If no
           signal in _set_ is pending at the time of the call, the thread shall
           be suspended until one or more becomes pending. The signals
           defined by _set_ shall have been blocked at the time of the call to
           _sigwait_(); otherwise, the behavior is undefined. The effect of
           _sigwait_() on the signal actions for the signals in _set_ is
           unspecified.
    
           If more than one thread is using _sigwait_() to wait for the same
           signal, no more than one of these threads shall return from
           _sigwait_() with the signal number. If more than a single thread is
           blocked in _sigwait_() for a signal when that signal is generated
           for the process, it is unspecified which of the waiting threads
           returns from _sigwait_().  If the signal is generated for a specific
           thread, as by _pthread_kill_(), only that thread shall return.
    
           Should any of the multiple pending signals in the range SIGRTMIN
           to SIGRTMAX be selected, it shall be the lowest numbered one. The
           selection order between realtime and non-realtime signals, or
           between multiple pending non-realtime signals, is unspecified.
    


## RETURN VALUE



           Upon successful completion, _sigwait_() shall store the signal
           number of the received signal at the location referenced by _sig_
           and return zero. Otherwise, an error number shall be returned to
           indicate the error.
    


## ERRORS



           The _sigwait_() function may fail if:
    
           **EINVAL** The _set_ argument contains an invalid or unsupported signal
                  number.
    
           _The following sections are informative._
    


## EXAMPLES



           None.
    


## APPLICATION USAGE



           None.
    


## RATIONALE



           To provide a convenient way for a thread to wait for a signal,
           this volume of POSIX.1‐2017 provides the _sigwait_() function. For
           most cases where a thread has to wait for a signal, the _sigwait_()
           function should be quite convenient, efficient, and adequate.
    
           However, requests were made for a lower-level primitive than
           _sigwait_() and for semaphores that could be used by threads. After
           some consideration, threads were allowed to use semaphores and
           _sem_post_() was defined to be async-signal-safe.
    
           In summary, when it is necessary for code run in response to an
           asynchronous signal to notify a thread, _sigwait_() should be used
           to handle the signal. Alternatively, if the implementation
           provides semaphores, they also can be used, either following
           _sigwait_() or from within a signal handling routine previously
           registered with _sigaction_().
    


## FUTURE DIRECTIONS



           None.
    


* * *