xref: /netbsd-src/lib/libpthread/pthread.3 (revision 661e3b515951b1cf67bf9e9a9d06b3f8932a6b39)
1.\"	$NetBSD: pthread.3,v 1.18 2017/10/23 01:03:23 wiz Exp $
2.\"
3.\" Copyright (c) 2003, 2007, 2009 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Hubert Feyrer <hubertf@NetBSD.org> and Thomas Klausner <wiz@NetBSD.org>.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28.\" POSSIBILITY OF SUCH DAMAGE.
29.\"
30.Dd November 22, 2016
31.Dt PTHREAD 3
32.Os
33.Sh NAME
34.Nm pthread
35.Nd POSIX Threads Library
36.Sh LIBRARY
37.Lb libpthread
38.Sh SYNOPSIS
39.In pthread.h
40.Pp
41.Nm cc
42.Op Ar flags
43.Ar files
44.Fl lpthread
45.Op Ar libraries
46.Sh DESCRIPTION
47The
48.Nm
49library provides an implementation of the standard POSIX threads
50library.
51.Pp
52The
53.Nx
54implementation is based on 1:1 thread model, therefore each
55.Nm
56has a kernel thread, called a light-weight process (LWP).
57.Pp
58Note that the system private thread interfaces upon which the
59.Nm
60library is built are subject to change without notice.
61In order to remain compatible with future
62.Nx
63releases, programs must be linked against the dynamic version of the
64thread library.
65Statically linked programs using the POSIX
66threads framework may not work when run on a future version of the system.
67.Sh FUNCTIONS
68The following functions comprise the core of the
69.Nm
70library:
71.Bl -column -offset indent "pthread_barrier_destroy(3)" "XXX"
72.It Sy Function Ta Sy Description
73.It Xr pthread_attr 3 Ta thread attribute operations
74.It Xr pthread_barrier_destroy 3 Ta destroy a barrier
75.It Xr pthread_barrier_init 3 Ta create a barrier
76.It Xr pthread_barrier_wait 3 Ta wait for a barrier
77.It Xr pthread_barrierattr 3 Ta barrier attribute operations
78.It Xr pthread_cancel 3 Ta cancel the execution of a thread
79.It Xr pthread_cleanup_push 3 Ta add or remove cleanup functions
80.It Xr pthread_cond_broadcast 3 Ta unblock one or more threads
81.It Xr pthread_cond_destroy 3 Ta destroy a condition variable
82.It Xr pthread_cond_init 3 Ta create a condition variable
83.It Xr pthread_cond_wait 3 Ta wait for a condition variable
84.It Xr pthread_condattr 3 Ta condition attribute operations
85.It Xr pthread_create 3 Ta create a new thread
86.It Xr pthread_detach 3 Ta detach a thread
87.It Xr pthread_equal 3 Ta compare thread identifiers
88.It Xr pthread_exit 3 Ta terminate the calling thread
89.It Xr pthread_getspecific 3 Ta get a thread-specific data value
90.It Xr pthread_join 3 Ta wait for thread termination
91.It Xr pthread_key_create 3 Ta thread-specific data key creation
92.It Xr pthread_key_delete 3 Ta delete a thread-specific data key
93.It Xr pthread_kill 3 Ta send a signal to a specific thread
94.It Xr pthread_mutex_destroy 3 Ta free a mutex
95.It Xr pthread_mutex_init 3 Ta create a mutex
96.It Xr pthread_mutex_lock 3 Ta acquire a lock on a mutex
97.It Xr pthread_mutex_unlock 3 Ta unlock a mutex
98.It Xr pthread_mutexattr 3 Ta mutex attribute operations
99.It Xr pthread_once 3 Ta dynamic package initialization
100.It Xr pthread_rwlock_destroy 3 Ta destroy a read/write lock
101.It Xr pthread_rwlock_init 3 Ta initialize a read/write lock
102.It Xr pthread_rwlock_rdlock 3 Ta acquire a read/write lock for reading
103.It Xr pthread_rwlock_unlock 3 Ta release a read/write lock
104.It Xr pthread_rwlock_wrlock 3 Ta acquire a read/write lock for writing
105.It Xr pthread_rwlockattr 3 Ta read/write lock attribute operations
106.It Xr pthread_schedparam 3 Ta thread scheduling manipulation
107.It Xr pthread_self 3 Ta get the ID of the calling thread
108.It Xr pthread_setspecific 3 Ta get a thread-specific data value
109.It Xr pthread_sigmask 3 Ta manipulate a thread's signal mask
110.It Xr pthread_spin_destroy 3 Ta destroy a spin lock
111.It Xr pthread_spin_init 3 Ta initialize a spin lock
112.It Xr pthread_spin_lock 3 Ta acquire a spin lock
113.It Xr pthread_spin_unlock 3 Ta release a spin lock
114.It Xr pthread_testcancel 3 Ta set cancelability state
115.El
116.Sh ENVIRONMENT
117The following environment variables affect the behavior of the library:
118.Bl -tag -width "XXX"
119.It Ev PTHREAD_DIAGASSERT
120Possible values are any combinations of:
121.Pp
122.Bl -tag -width "X " -offset 1n -compact
123.It Em A
124Report errors to application by error return, but do not abort.
125.It Em a
126Abort on errors, creating a core dump for further debugging.
127.It Em E
128Do not log errors to stdout.
129.It Em e
130Log errors to stdout.
131.It Em L
132Do not log errors via
133.Xr syslogd 8 .
134.It Em l
135Log errors via
136.Xr syslogd 8 .
137.El
138.Pp
139If not set in the environment, the
140.Nm
141library behaves as if
142.Em AEL
143has been specified.
144.It Ev PTHREAD_STACKSIZE
145Integer value giving the stack size in kilobytes.
146This allows to set a smaller stack size than the default stack size.
147The default stack size is the current limit on the stack size as
148set with the shell's command to change limits
149.Ic ( limit
150for
151.Xr csh 1 ,
152or
153.Ic ulimit
154for
155.Xr sh 1 ) .
156.El
157.Sh SEE ALSO
158.Rs
159.%A David R. Butenhof
160.%T Programming with POSIX(R) Threads
161.%D 1997
162.%I Addison-Wesley
163.Re
164.Sh STANDARDS
165The
166.Nm
167library conforms to
168.St -p1003.1-2001 .
169.Sh CAVEATS
170Due to limitations in the current pthread implementation,
171.Xr makecontext 3
172and
173.Xr sigaltstack 2
174should not be used in programs which link against the
175.Nm
176library (whether threads are used or not).
177