xref: /netbsd-src/lib/libpthread/pthread.3 (revision 661e3b515951b1cf67bf9e9a9d06b3f8932a6b39)
1*661e3b51Swiz.\"	$NetBSD: pthread.3,v 1.18 2017/10/23 01:03:23 wiz Exp $
2576530e5Swiz.\"
38b5179c2Swiz.\" Copyright (c) 2003, 2007, 2009 The NetBSD Foundation, Inc.
4576530e5Swiz.\" All rights reserved.
5576530e5Swiz.\"
604845dabSwiz.\" This code is derived from software contributed to The NetBSD Foundation
704845dabSwiz.\" by Hubert Feyrer <hubertf@NetBSD.org> and Thomas Klausner <wiz@NetBSD.org>.
804845dabSwiz.\"
9576530e5Swiz.\" Redistribution and use in source and binary forms, with or without
10576530e5Swiz.\" modification, are permitted provided that the following conditions
11576530e5Swiz.\" are met:
12576530e5Swiz.\" 1. Redistributions of source code must retain the above copyright
13576530e5Swiz.\"    notice, this list of conditions and the following disclaimer.
14576530e5Swiz.\" 2. Redistributions in binary form must reproduce the above copyright
15576530e5Swiz.\"    notice, this list of conditions and the following disclaimer in the
16576530e5Swiz.\"    documentation and/or other materials provided with the distribution.
17576530e5Swiz.\"
1804845dabSwiz.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1904845dabSwiz.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2004845dabSwiz.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2104845dabSwiz.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2204845dabSwiz.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2304845dabSwiz.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2404845dabSwiz.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2504845dabSwiz.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2604845dabSwiz.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2704845dabSwiz.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2804845dabSwiz.\" POSSIBILITY OF SUCH DAMAGE.
29576530e5Swiz.\"
30fe65e38bSwiz.Dd November 22, 2016
31576530e5Swiz.Dt PTHREAD 3
32576530e5Swiz.Os
33576530e5Swiz.Sh NAME
34576530e5Swiz.Nm pthread
35576530e5Swiz.Nd POSIX Threads Library
36576530e5Swiz.Sh LIBRARY
37576530e5Swiz.Lb libpthread
38576530e5Swiz.Sh SYNOPSIS
39576530e5Swiz.In pthread.h
40576530e5Swiz.Pp
41576530e5Swiz.Nm cc
42576530e5Swiz.Op Ar flags
43576530e5Swiz.Ar files
44576530e5Swiz.Fl lpthread
45576530e5Swiz.Op Ar libraries
46576530e5Swiz.Sh DESCRIPTION
47576530e5SwizThe
48576530e5Swiz.Nm
49*661e3b51Swizlibrary provides an implementation of the standard POSIX threads
50*661e3b51Swizlibrary.
5126ce5a50Srmind.Pp
5226ce5a50SrmindThe
5326ce5a50Srmind.Nx
5426ce5a50Srmindimplementation is based on 1:1 thread model, therefore each
5526ce5a50Srmind.Nm
5626ce5a50Srmindhas a kernel thread, called a light-weight process (LWP).
57a4c99db9Sad.Pp
58a4c99db9SadNote that the system private thread interfaces upon which the
59a4c99db9Sad.Nm
60a4c99db9Sadlibrary is built are subject to change without notice.
61a4c99db9SadIn order to remain compatible with future
62a4c99db9Sad.Nx
63a4c99db9Sadreleases, programs must be linked against the dynamic version of the
64a4c99db9Sadthread library.
65*661e3b51SwizStatically linked programs using the POSIX
66a4c99db9Sadthreads framework may not work when run on a future version of the system.
678292b0e6Sjruoho.Sh FUNCTIONS
688292b0e6SjruohoThe following functions comprise the core of the
698292b0e6Sjruoho.Nm
708292b0e6Sjruoholibrary:
718292b0e6Sjruoho.Bl -column -offset indent "pthread_barrier_destroy(3)" "XXX"
728292b0e6Sjruoho.It Sy Function Ta Sy Description
738292b0e6Sjruoho.It Xr pthread_attr 3 Ta thread attribute operations
748292b0e6Sjruoho.It Xr pthread_barrier_destroy 3 Ta destroy a barrier
758292b0e6Sjruoho.It Xr pthread_barrier_init 3 Ta create a barrier
768292b0e6Sjruoho.It Xr pthread_barrier_wait 3 Ta wait for a barrier
778292b0e6Sjruoho.It Xr pthread_barrierattr 3 Ta barrier attribute operations
788292b0e6Sjruoho.It Xr pthread_cancel 3 Ta cancel the execution of a thread
798292b0e6Sjruoho.It Xr pthread_cleanup_push 3 Ta add or remove cleanup functions
808292b0e6Sjruoho.It Xr pthread_cond_broadcast 3 Ta unblock one or more threads
818292b0e6Sjruoho.It Xr pthread_cond_destroy 3 Ta destroy a condition variable
828292b0e6Sjruoho.It Xr pthread_cond_init 3 Ta create a condition variable
838292b0e6Sjruoho.It Xr pthread_cond_wait 3 Ta wait for a condition variable
848292b0e6Sjruoho.It Xr pthread_condattr 3 Ta condition attribute operations
858292b0e6Sjruoho.It Xr pthread_create 3 Ta create a new thread
868292b0e6Sjruoho.It Xr pthread_detach 3 Ta detach a thread
878292b0e6Sjruoho.It Xr pthread_equal 3 Ta compare thread identifiers
888292b0e6Sjruoho.It Xr pthread_exit 3 Ta terminate the calling thread
898292b0e6Sjruoho.It Xr pthread_getspecific 3 Ta get a thread-specific data value
908292b0e6Sjruoho.It Xr pthread_join 3 Ta wait for thread termination
918292b0e6Sjruoho.It Xr pthread_key_create 3 Ta thread-specific data key creation
928292b0e6Sjruoho.It Xr pthread_key_delete 3 Ta delete a thread-specific data key
938292b0e6Sjruoho.It Xr pthread_kill 3 Ta send a signal to a specific thread
948292b0e6Sjruoho.It Xr pthread_mutex_destroy 3 Ta free a mutex
958292b0e6Sjruoho.It Xr pthread_mutex_init 3 Ta create a mutex
968292b0e6Sjruoho.It Xr pthread_mutex_lock 3 Ta acquire a lock on a mutex
978292b0e6Sjruoho.It Xr pthread_mutex_unlock 3 Ta unlock a mutex
988292b0e6Sjruoho.It Xr pthread_mutexattr 3 Ta mutex attribute operations
998292b0e6Sjruoho.It Xr pthread_once 3 Ta dynamic package initialization
1008292b0e6Sjruoho.It Xr pthread_rwlock_destroy 3 Ta destroy a read/write lock
1018292b0e6Sjruoho.It Xr pthread_rwlock_init 3 Ta initialize a read/write lock
1028292b0e6Sjruoho.It Xr pthread_rwlock_rdlock 3 Ta acquire a read/write lock for reading
1038292b0e6Sjruoho.It Xr pthread_rwlock_unlock 3 Ta release a read/write lock
1048292b0e6Sjruoho.It Xr pthread_rwlock_wrlock 3 Ta acquire a read/write lock for writing
1058292b0e6Sjruoho.It Xr pthread_rwlockattr 3 Ta read/write lock attribute operations
1068292b0e6Sjruoho.It Xr pthread_schedparam 3 Ta thread scheduling manipulation
1078292b0e6Sjruoho.It Xr pthread_self 3 Ta get the ID of the calling thread
1088292b0e6Sjruoho.It Xr pthread_setspecific 3 Ta get a thread-specific data value
1098292b0e6Sjruoho.It Xr pthread_sigmask 3 Ta manipulate a thread's signal mask
1108292b0e6Sjruoho.It Xr pthread_spin_destroy 3 Ta destroy a spin lock
1118292b0e6Sjruoho.It Xr pthread_spin_init 3 Ta initialize a spin lock
1128292b0e6Sjruoho.It Xr pthread_spin_lock 3 Ta acquire a spin lock
1138292b0e6Sjruoho.It Xr pthread_spin_unlock 3 Ta release a spin lock
1148292b0e6Sjruoho.It Xr pthread_testcancel 3 Ta set cancelability state
1158292b0e6Sjruoho.El
116576530e5Swiz.Sh ENVIRONMENT
1178292b0e6SjruohoThe following environment variables affect the behavior of the library:
1188292b0e6Sjruoho.Bl -tag -width "XXX"
119576530e5Swiz.It Ev PTHREAD_DIAGASSERT
120576530e5SwizPossible values are any combinations of:
1218572b64aSad.Pp
1228292b0e6Sjruoho.Bl -tag -width "X " -offset 1n -compact
1238292b0e6Sjruoho.It Em A
1248572b64aSadReport errors to application by error return, but do not abort.
1258292b0e6Sjruoho.It Em a
126576530e5SwizAbort on errors, creating a core dump for further debugging.
1278292b0e6Sjruoho.It Em E
128576530e5SwizDo not log errors to stdout.
1298292b0e6Sjruoho.It Em e
130576530e5SwizLog errors to stdout.
1318292b0e6Sjruoho.It Em L
132576530e5SwizDo not log errors via
133576530e5Swiz.Xr syslogd 8 .
1348292b0e6Sjruoho.It Em l
135576530e5SwizLog errors via
136576530e5Swiz.Xr syslogd 8 .
137576530e5Swiz.El
1388572b64aSad.Pp
1398572b64aSadIf not set in the environment, the
1408572b64aSad.Nm
1418572b64aSadlibrary behaves as if
1428292b0e6Sjruoho.Em AEL
1438572b64aSadhas been specified.
1442c9b7b1eScl.It Ev PTHREAD_STACKSIZE
1452c9b7b1eSclInteger value giving the stack size in kilobytes.
1462c9b7b1eSclThis allows to set a smaller stack size than the default stack size.
1472c9b7b1eSclThe default stack size is the current limit on the stack size as
1482c9b7b1eSclset with the shell's command to change limits
1492c9b7b1eScl.Ic ( limit
1502c9b7b1eSclfor
1512c9b7b1eScl.Xr csh 1 ,
1522c9b7b1eSclor
1532c9b7b1eScl.Ic ulimit
1542c9b7b1eSclfor
1552c9b7b1eScl.Xr sh 1 ) .
156576530e5Swiz.El
157e55b912bSjruoho.Sh SEE ALSO
158e55b912bSjruoho.Rs
159e55b912bSjruoho.%A David R. Butenhof
160e55b912bSjruoho.%T Programming with POSIX(R) Threads
161e55b912bSjruoho.%D 1997
162e55b912bSjruoho.%I Addison-Wesley
163e55b912bSjruoho.Re
164576530e5Swiz.Sh STANDARDS
165576530e5SwizThe
166576530e5Swiz.Nm
167576530e5Swizlibrary conforms to
168576530e5Swiz.St -p1003.1-2001 .
1698b5179c2Swiz.Sh CAVEATS
1708b5179c2SwizDue to limitations in the current pthread implementation,
1718b5179c2Swiz.Xr makecontext 3
1728b5179c2Swizand
1738b5179c2Swiz.Xr sigaltstack 2
1748b5179c2Swizshould not be used in programs which link against the
1758b5179c2Swiz.Nm
1768b5179c2Swizlibrary (whether threads are used or not).
177