]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/pthread_sigmask.3
dlinfo.3: ATTRIBUTES: Note function that is thread-safe
[thirdparty/man-pages.git] / man3 / pthread_sigmask.3
CommitLineData
b4ed7957
MK
1.\" Copyright (c) 2009 Linux Foundation, written by Michael Kerrisk
2.\" <mtk.manpages@gmail.com>
3.\"
93015253 4.\" %%%LICENSE_START(VERBATIM)
b4ed7957
MK
5.\" Permission is granted to make and distribute verbatim copies of this
6.\" manual provided the copyright notice and this permission notice are
7.\" preserved on all copies.
8.\"
9.\" Permission is granted to copy and distribute modified versions of this
10.\" manual under the conditions for verbatim copying, provided that the
11.\" entire resulting derived work is distributed under the terms of a
12.\" permission notice identical to this one.
13.\"
14.\" Since the Linux kernel and libraries are constantly changing, this
15.\" manual page may be incorrect or out-of-date. The author(s) assume no
16.\" responsibility for errors or omissions, or for damages resulting from
17.\" the use of the information contained herein. The author(s) may not
18.\" have taken the same level of care in the production of this manual,
19.\" which is licensed free of charge, as they might when working
20.\" professionally.
21.\"
22.\" Formatted or processed versions of this manual, if unaccompanied by
23.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 24.\" %%%LICENSE_END
b4ed7957 25.\"
fe0fefbf 26.TH PTHREAD_SIGMASK 3 2015-03-02 "Linux" "Linux Programmer's Manual"
b4ed7957
MK
27.SH NAME
28pthread_sigmask \- examine and change mask of blocked signals
29.SH SYNOPSIS
30.nf
31.B #include <signal.h>
32
33.BI "int pthread_sigmask(int " how ", const sigset_t *" set \
34", sigset_t *" oldset );
35.fi
36.sp
37Compile and link with \fI\-pthread\fP.
fc1d1e69
MK
38.sp
39.in -4n
40Feature Test Macro Requirements for glibc (see
41.BR feature_test_macros (7)):
42.in
43.sp
44.ad l
45.BR pthread_sigmask ():
46.RS 4
47_POSIX_C_SOURCE\ >=\ 199506L || _XOPEN_SOURCE\ >=\ 500
48.RE
49.ad b
b4ed7957
MK
50.SH DESCRIPTION
51The
52.BR pthread_sigmask ()
53function is just like
54.BR sigprocmask (2),
55with the difference that its use in multithreaded programs
3196395a 56is explicitly specified by POSIX.1.
b4ed7957
MK
57Other differences are noted in this page.
58
59For a description of the arguments and operation of this function, see
60.BR sigprocmask (2).
61.SH RETURN VALUE
62On success,
63.BR pthread_sigmask ()
64returns 0;
65on error, it returns an error number.
66.SH ERRORS
67See
68.BR sigprocmask (2).
21f80449 69.SH ATTRIBUTES
f5104723
PH
70For an explanation of the terms used in this section, see
71.BR attributes (7).
72.TS
73allbox;
74lb lb lb
75l l l.
76Interface Attribute Value
77T{
21f80449 78.BR pthread_sigmask ()
f5104723
PH
79T} Thread safety MT-Safe
80.TE
b4ed7957 81.SH CONFORMING TO
3196395a 82POSIX.1-2001, POSIX.1-2008.
b4ed7957
MK
83.SH NOTES
84A new thread inherits a copy of its creator's signal mask.
bce38798
MK
85
86The glibc
87.BR pthread_sigmask ()
88function silently ignores attempts to block the two real-time signals that
89are used internally by the NPTL threading implementation.
90See
91.BR nptl (7)
92for details.
b4ed7957
MK
93.SH EXAMPLE
94The program below blocks some signals in the main thread,
95and then creates a dedicated thread to fetch those signals via
96.BR sigwait (3).
97The following shell session demonstrates its use:
98
99.in +4n
100.nf
101.RB "$" " ./a.out &"
102[1] 5423
103.RB "$" " kill \-QUIT %1"
104Signal handling thread got signal 3
105.RB "$" " kill \-USR1 %1"
106Signal handling thread got signal 10
107.RB "$" " kill \-TERM %1"
108[1]+ Terminated ./a.out
109.fi
110.in
111.SS Program source
112\&
113.nf
114#include <pthread.h>
115#include <stdio.h>
116#include <stdlib.h>
117#include <unistd.h>
118#include <signal.h>
119#include <errno.h>
120
121/* Simple error handling functions */
122
123#define handle_error_en(en, msg) \\
124 do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0)
125
126static void *
127sig_thread(void *arg)
128{
13f78d96 129 sigset_t *set = arg;
b4ed7957
MK
130 int s, sig;
131
132 for (;;) {
133 s = sigwait(set, &sig);
134 if (s != 0)
135 handle_error_en(s, "sigwait");
136 printf("Signal handling thread got signal %d\\n", sig);
137 }
138}
139
140int
141main(int argc, char *argv[])
142{
143 pthread_t thread;
144 sigset_t set;
145 int s;
146
4a905b92
MK
147 /* Block SIGQUIT and SIGUSR1; other threads created by main()
148 will inherit a copy of the signal mask. */
b4ed7957
MK
149
150 sigemptyset(&set);
151 sigaddset(&set, SIGQUIT);
152 sigaddset(&set, SIGUSR1);
153 s = pthread_sigmask(SIG_BLOCK, &set, NULL);
154 if (s != 0)
155 handle_error_en(s, "pthread_sigmask");
156
157 s = pthread_create(&thread, NULL, &sig_thread, (void *) &set);
158 if (s != 0)
159 handle_error_en(s, "pthread_create");
160
161 /* Main thread carries on to create other threads and/or do
162 other work */
163
164 pause(); /* Dummy pause so we can test program */
165}
166.fi
167.SH SEE ALSO
168.BR sigaction (2),
169.BR sigpending (2),
9e88dbc3 170.BR sigprocmask (2),
b4ed7957
MK
171.BR pthread_create (3),
172.BR pthread_kill (3),
173.BR sigsetops (3),
174.BR pthreads (7),
175.BR signal (7)