The sigwait() function shall select a pending signal from 'set', automatically
clear it from the system's pending signals, and return that signal number in
the location represendted by 'sig'.
If prior to the call to sigwait() there are multiple pending instances of a
single signal number (and it is implementation-defined that the signal number
supports queued signals), then the first such queued signal shall cause a
return from sigwait() and the remainder shall remain queued.
If prior to the call to sigwait() there are multiple pending instances of a
single signal number (and it is implementation-defined that the signal number
DOES NOT support queued signals), then there should be no remaining pending
signals for that signal number.
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' should 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.
Which thread returns from sigwait() is unspecified if the signal is generated
for the process; otherwise only the target thread of the signal can receive the
signal.
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 real
time and non-realtime signals, or between multiple pending non-realtime signals is unspecified.
Upon successful completion, sigwait() shall store the signal number of the
received signal at the location referenced by 'sig' and return zero.
Upon unsuccess, sigwait() will return with a non-zero error number to indicate
the error.
The sigwait() function fails if the 'set' argument contains an invalid
or unsupported signal number.