summaryrefslogtreecommitdiffstats
path: root/man-pages-posix-2013/man3p/sigwait.3p
blob: 1fe7ad5243a02e5ee45ed4c7f933e8a51abc567d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
'\" et
.TH SIGWAIT "3P" 2013 "IEEE/The Open Group" "POSIX Programmer's Manual"
.SH 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.

.SH NAME
sigwait
\(em wait for queued signals
.SH SYNOPSIS
.LP
.nf
#include <signal.h>
.P
int sigwait(const sigset_t *restrict \fIset\fP, int *restrict \fIsig\fP);
.fi
.SH DESCRIPTION
The
\fIsigwait\fR()
function shall select a pending signal from
.IR set ,
atomically clear it from the system's set of pending signals, and
return that signal number in the location referenced by
.IR sig .
If prior to the call to
\fIsigwait\fR()
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
\fIsigwait\fR()
and the remainder shall remain queued. If no signal in
.IR set
is pending at the time of the call, the thread shall be suspended
until one or more becomes pending. The signals defined by
.IR set
shall have been blocked at the time of the call to
\fIsigwait\fR();
otherwise, the behavior is undefined. The effect of
\fIsigwait\fR()
on the signal actions for the signals in
.IR set
is unspecified.
.P
If more than one thread is using
\fIsigwait\fR()
to wait for the same signal, no more than one of these threads shall
return from
\fIsigwait\fR()
with the signal number. If more than a single thread is blocked in
\fIsigwait\fR()
for a signal when that signal is generated for the process, it is
unspecified which of the waiting threads returns from
\fIsigwait\fR().
If the signal is generated for a specific thread, as by
\fIpthread_kill\fR(),
only that thread shall return.
.P
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.
.SH "RETURN VALUE"
Upon successful completion,
\fIsigwait\fR()
shall store the signal number of the received signal at the location
referenced by
.IR sig
and return zero. Otherwise, an error number shall be returned to
indicate the error.
.SH ERRORS
The
\fIsigwait\fR()
function may fail if:
.TP
.BR EINVAL
The
.IR set
argument contains an invalid or unsupported signal number.
.LP
.IR "The following sections are informative."
.SH EXAMPLES
None.
.SH "APPLICATION USAGE"
None.
.SH RATIONALE
To provide a convenient way for a thread to wait for a signal, this volume of POSIX.1\(hy2008
provides the
\fIsigwait\fR()
function. For most cases where a thread has to wait for a signal, the
\fIsigwait\fR()
function should be quite convenient, efficient, and adequate.
.P
However, requests were made for a lower-level primitive than
\fIsigwait\fR()
and for semaphores that could be used by threads. After some
consideration, threads were allowed to use semaphores and
\fIsem_post\fR()
was defined to be async-signal-safe.
.P
In summary, when it is necessary for code run in response to an
asynchronous signal to notify a thread,
\fIsigwait\fR()
should be used to handle the signal. Alternatively, if the
implementation provides semaphores, they also can be used, either
following
\fIsigwait\fR()
or from within a signal handling routine previously registered with
\fIsigaction\fR().
.SH "FUTURE DIRECTIONS"
None.
.SH "SEE ALSO"
.IR "Section 2.4" ", " "Signal Concepts",
.IR "Section 2.8.1" ", " "Realtime Signals",
.IR "\fIpause\fR\^(\|)",
.IR "\fIpthread_sigmask\fR\^(\|)",
.IR "\fIsigaction\fR\^(\|)",
.IR "\fIsigpending\fR\^(\|)",
.IR "\fIsigsuspend\fR\^(\|)",
.IR "\fIsigtimedwait\fR\^(\|)"
.P
The Base Definitions volume of POSIX.1\(hy2008,
.IR "\fB<signal.h>\fP",
.IR "\fB<time.h>\fP"
.SH COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form
from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
-- Portable Operating System Interface (POSIX), The Open Group Base
Specifications Issue 7, Copyright (C) 2013 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group.
(This is POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
event of any discrepancy between this version and the original IEEE and
The Open Group Standard, the original IEEE and The Open Group Standard
is the referee document. The original Standard can be obtained online at
http://www.unix.org/online.html .

Any typographical or formatting errors that appear
in this page are most likely
to have been introduced during the conversion of the source files to
man page format. To report such errors, see
https://www.kernel.org/doc/man-pages/reporting_bugs.html .