10f7d6847SJulian Elischer.\" Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>. 20f7d6847SJulian Elischer.\" All rights reserved. 30f7d6847SJulian Elischer.\" 40f7d6847SJulian Elischer.\" Redistribution and use in source and binary forms, with or without 50f7d6847SJulian Elischer.\" modification, are permitted provided that the following conditions 60f7d6847SJulian Elischer.\" are met: 70f7d6847SJulian Elischer.\" 1. Redistributions of source code must retain the above copyright 80f7d6847SJulian Elischer.\" notice, this list of conditions and the following disclaimer. 90f7d6847SJulian Elischer.\" 2. Redistributions in binary form must reproduce the above copyright 100f7d6847SJulian Elischer.\" notice, this list of conditions and the following disclaimer in the 110f7d6847SJulian Elischer.\" documentation and/or other materials provided with the distribution. 120f7d6847SJulian Elischer.\" 3. All advertising materials mentioning features or use of this software 130f7d6847SJulian Elischer.\" must display the following acknowledgement: 140f7d6847SJulian Elischer.\" This product includes software developed by John Birrell. 150f7d6847SJulian Elischer.\" 4. Neither the name of the author nor the names of any co-contributors 160f7d6847SJulian Elischer.\" may be used to endorse or promote products derived from this software 170f7d6847SJulian Elischer.\" without specific prior written permission. 180f7d6847SJulian Elischer.\" 190f7d6847SJulian Elischer.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 200f7d6847SJulian Elischer.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 210f7d6847SJulian Elischer.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 220f7d6847SJulian Elischer.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 230f7d6847SJulian Elischer.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 240f7d6847SJulian Elischer.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 250f7d6847SJulian Elischer.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 260f7d6847SJulian Elischer.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 270f7d6847SJulian Elischer.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 280f7d6847SJulian Elischer.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 290f7d6847SJulian Elischer.\" SUCH DAMAGE. 300f7d6847SJulian Elischer.\" 317f3dea24SPeter Wemm.\" $FreeBSD$ 32ac5afce1SJohn-Mark Gurney.\" 33d4a76febSAlexander Langer.Dd September 10, 1998 340f7d6847SJulian Elischer.Dt PTHREAD 3 350f7d6847SJulian Elischer.Os BSD 4 360f7d6847SJulian Elischer.Sh NAME 370f7d6847SJulian Elischer.Nm pthread 380f7d6847SJulian Elischer.Nd POSIX thread functions 39c70db3ffSBruce Evans.Sh SYNOPSIS 40c70db3ffSBruce Evans.Fd #include <pthread.h> 410f7d6847SJulian Elischer.Sh DESCRIPTION 420f7d6847SJulian ElischerPOSIX threads are a set of functions that support applications with 430f7d6847SJulian Elischerrequirements for multiple flows of control, called 440f7d6847SJulian Elischer.Fa threads , 456d249eeeSSheldon Hearnwithin a process. 466d249eeeSSheldon HearnMultithreading is used to improve the performance of a 470f7d6847SJulian Elischerprogram. 480f7d6847SJulian Elischer.Pp 490f7d6847SJulian ElischerThe POSIX thread functions are summarized in this section in the following 500f7d6847SJulian Elischergroups: 510f7d6847SJulian Elischer.Bl -bullet -offset indent 520f7d6847SJulian Elischer.It 53d4a76febSAlexander LangerThread Routines 540f7d6847SJulian Elischer.It 550f7d6847SJulian ElischerAttribute Object Routines 560f7d6847SJulian Elischer.It 570f7d6847SJulian ElischerMutex Routines 580f7d6847SJulian Elischer.It 590f7d6847SJulian ElischerCondition Variable Routines 600f7d6847SJulian Elischer.It 61d4a76febSAlexander LangerRead/Write Lock Routines 62d4a76febSAlexander Langer.It 630f7d6847SJulian ElischerPer-Thread Context Routines 640f7d6847SJulian Elischer.It 650f7d6847SJulian ElischerCleanup Routines 660f7d6847SJulian Elischer.El 670f7d6847SJulian Elischer.Sh THREAD ROUTINES 680f7d6847SJulian Elischer.Bl -tag -width Er 69d0353b83SRuslan Ermilov.It Xo 70d0353b83SRuslan Ermilov.Ft int 71d0353b83SRuslan Ermilov.Fn pthread_create "pthread_t *thread" "const pthread_attr_t *attr" "void *(*start_routine)(void *)" "void *arg" 72d0353b83SRuslan Ermilov.Xc 730f7d6847SJulian ElischerCreates a new thread of execution. 74d0353b83SRuslan Ermilov.It Xo 75d0353b83SRuslan Ermilov.Ft int 76d0353b83SRuslan Ermilov.Fn pthread_detach "pthread_t thread" 77d0353b83SRuslan Ermilov.Xc 780f7d6847SJulian ElischerMarks a thread for deletion. 79d0353b83SRuslan Ermilov.It Xo 80d0353b83SRuslan Ermilov.Ft int 81d0353b83SRuslan Ermilov.Fn pthread_equal "pthread_t t1" "pthread_t t2" 82d0353b83SRuslan Ermilov.Xc 830f7d6847SJulian ElischerCompares two thread IDs. 84d0353b83SRuslan Ermilov.It Xo 85d0353b83SRuslan Ermilov.Ft void 86d0353b83SRuslan Ermilov.Fn pthread_exit "void *value_ptr" 87d0353b83SRuslan Ermilov.Xc 880f7d6847SJulian ElischerTerminates the calling thread. 89d0353b83SRuslan Ermilov.It Xo 90d0353b83SRuslan Ermilov.Ft int 91d0353b83SRuslan Ermilov.Fn pthread_join "pthread_t thread" "void **value_ptr" 92d0353b83SRuslan Ermilov.Xc 930f7d6847SJulian ElischerCauses the calling thread to wait for the termination of the specified thread. 94d0353b83SRuslan Ermilov.It Xo 95d0353b83SRuslan Ermilov.Ft int 96d0353b83SRuslan Ermilov.Fn pthread_cancel "pthread_t thread" 97d0353b83SRuslan Ermilov.Xc 98ddb9c6cdSChris CostelloCancels execution of a thread. 99d0353b83SRuslan Ermilov.It Xo 100d0353b83SRuslan Ermilov.Ft int 101d0353b83SRuslan Ermilov.Fn pthread_once "pthread_once_t *once_control" "void (*init_routine)(void)" 102d0353b83SRuslan Ermilov.Xc 1030f7d6847SJulian ElischerCalls an initialization routine once. 104d0353b83SRuslan Ermilov.It Xo 105d0353b83SRuslan Ermilov.Ft pthread_t 106d0353b83SRuslan Ermilov.Fn pthread_self void 107d0353b83SRuslan Ermilov.Xc 1080f7d6847SJulian ElischerReturns the thread ID of the calling thread. 1090f7d6847SJulian Elischer.El 1100f7d6847SJulian Elischer.Sh ATTRIBUTE OBJECT ROUTINES 1110f7d6847SJulian Elischer.Bl -tag -width Er 112d0353b83SRuslan Ermilov.It Xo 113d0353b83SRuslan Ermilov.Ft int 114d0353b83SRuslan Ermilov.Fn pthread_attr_destroy "pthread_attr_t *attr" 115d0353b83SRuslan Ermilov.Xc 1160f7d6847SJulian ElischerDestroy a thread attributes object. 117d0353b83SRuslan Ermilov.It Xo 118d0353b83SRuslan Ermilov.Ft int 119c70db3ffSBruce Evans.Fn pthread_attr_getinheritsched "const pthread_attr_t *attr" "int *inheritsched" 120d0353b83SRuslan Ermilov.Xc 1210f7d6847SJulian ElischerGet the inherit scheduling attribute from a thread attributes object. 122d0353b83SRuslan Ermilov.It Xo 123d0353b83SRuslan Ermilov.Ft int 124c70db3ffSBruce Evans.Fn pthread_attr_getschedparam "const pthread_attr_t *attr" "struct sched_param *param" 125d0353b83SRuslan Ermilov.Xc 1260f7d6847SJulian ElischerGet the scheduling parameter attribute from a thread attributes object. 127d0353b83SRuslan Ermilov.It Xo 128d0353b83SRuslan Ermilov.Ft int 129c70db3ffSBruce Evans.Fn pthread_attr_getschedpolicy "const pthread_attr_t *attr" "int *policy" 130d0353b83SRuslan Ermilov.Xc 1310f7d6847SJulian ElischerGet the scheduling policy attribute from a thread attributes object. 132d0353b83SRuslan Ermilov.It Xo 133d0353b83SRuslan Ermilov.Ft int 134c70db3ffSBruce Evans.Fn pthread_attr_getscope "const pthread_attr_t *attr" "int *contentionscope" 135d0353b83SRuslan Ermilov.Xc 1360f7d6847SJulian ElischerGet the contention scope attribute from a thread attributes object. 137d0353b83SRuslan Ermilov.It Xo 138d0353b83SRuslan Ermilov.Ft int 139c70db3ffSBruce Evans.Fn pthread_attr_getstacksize "const pthread_attr_t *attr" "size_t *stacksize" 140d0353b83SRuslan Ermilov.Xc 1410f7d6847SJulian ElischerGet the stack size attribute from a thread attributes object. 142d0353b83SRuslan Ermilov.It Xo 143d0353b83SRuslan Ermilov.Ft int 144c70db3ffSBruce Evans.Fn pthread_attr_getstackaddr "const pthread_attr_t *attr" "void **stackaddr" 145d0353b83SRuslan Ermilov.Xc 1460f7d6847SJulian ElischerGet the stack address attribute from a thread attributes object. 147d0353b83SRuslan Ermilov.It Xo 148d0353b83SRuslan Ermilov.Ft int 149c70db3ffSBruce Evans.Fn pthread_attr_getdetachstate "const pthread_attr_t *attr" "int *detachstate" 150d0353b83SRuslan Ermilov.Xc 1510f7d6847SJulian ElischerGet the detach state attribute from a thread attributes object. 152d0353b83SRuslan Ermilov.It Xo 153d0353b83SRuslan Ermilov.Ft int 154d0353b83SRuslan Ermilov.Fn pthread_attr_init "pthread_attr_t *attr" 155d0353b83SRuslan Ermilov.Xc 1560f7d6847SJulian ElischerInitialize a thread attributes object with default values. 157d0353b83SRuslan Ermilov.It Xo 158d0353b83SRuslan Ermilov.Ft int 159d0353b83SRuslan Ermilov.Fn pthread_attr_setinheritsched "pthread_attr_t *attr" "int inheritsched" 160d0353b83SRuslan Ermilov.Xc 1610f7d6847SJulian ElischerSet the inherit scheduling attribute in a thread attributes object. 162d0353b83SRuslan Ermilov.It Xo 163d0353b83SRuslan Ermilov.Ft int 164c70db3ffSBruce Evans.Fn pthread_attr_setschedparam "pthread_attr_t *attr" "const struct sched_param *param" 165d0353b83SRuslan Ermilov.Xc 1660f7d6847SJulian ElischerSet the scheduling parameter attribute in a thread attributes object. 167d0353b83SRuslan Ermilov.It Xo 168d0353b83SRuslan Ermilov.Ft int 169d0353b83SRuslan Ermilov.Fn pthread_attr_setschedpolicy "pthread_attr_t *attr" "int policy" 170d0353b83SRuslan Ermilov.Xc 1710f7d6847SJulian ElischerSet the scheduling policy attribute in a thread attributes object. 172d0353b83SRuslan Ermilov.It Xo 173d0353b83SRuslan Ermilov.Ft int 174d0353b83SRuslan Ermilov.Fn pthread_attr_setscope "pthread_attr_t *attr" "int contentionscope" 175d0353b83SRuslan Ermilov.Xc 1760f7d6847SJulian ElischerSet the contention scope attribute in a thread attributes object. 177d0353b83SRuslan Ermilov.It Xo 178d0353b83SRuslan Ermilov.Ft int 179d0353b83SRuslan Ermilov.Fn pthread_attr_setstacksize "pthread_attr_t *attr" "size_t stacksize" 180d0353b83SRuslan Ermilov.Xc 1810f7d6847SJulian ElischerSet the stack size attribute in a thread attributes object. 182d0353b83SRuslan Ermilov.It Xo 183d0353b83SRuslan Ermilov.Ft int 184d0353b83SRuslan Ermilov.Fn pthread_attr_setstackaddr "pthread_attr_t *attr" "void *stackaddr" 185d0353b83SRuslan Ermilov.Xc 1860f7d6847SJulian ElischerSet the stack address attribute in a thread attributes object. 187d0353b83SRuslan Ermilov.It Xo 188d0353b83SRuslan Ermilov.Ft int 189d0353b83SRuslan Ermilov.Fn pthread_attr_setdetachstate "pthread_attr_t *attr" "int detachstate" 190d0353b83SRuslan Ermilov.Xc 1910f7d6847SJulian ElischerSet the detach state in a thread attributes object. 1920f7d6847SJulian Elischer.El 1930f7d6847SJulian Elischer.Sh MUTEX ROUTINES 1940f7d6847SJulian Elischer.Bl -tag -width Er 195d0353b83SRuslan Ermilov.It Xo 196d0353b83SRuslan Ermilov.Ft int 197d0353b83SRuslan Ermilov.Fn pthread_mutexattr_destroy "pthread_mutexattr_t *attr" 198d0353b83SRuslan Ermilov.Xc 1990f7d6847SJulian ElischerDestroy a mutex attributes object. 200d0353b83SRuslan Ermilov.It Xo 201d0353b83SRuslan Ermilov.Ft int 202d0353b83SRuslan Ermilov.Fn pthread_mutexattr_init "pthread_mutexattr_t *attr" 203d0353b83SRuslan Ermilov.Xc 2040f7d6847SJulian ElischerInitialize a mutex attributes object with default values. 205d0353b83SRuslan Ermilov.It Xo 206d0353b83SRuslan Ermilov.Ft int 207d0353b83SRuslan Ermilov.Fn pthread_mutex_destroy "pthread_mutex_t *mutex" 208d0353b83SRuslan Ermilov.Xc 2090f7d6847SJulian ElischerDestroy a mutex. 210d0353b83SRuslan Ermilov.It Xo 211d0353b83SRuslan Ermilov.Ft int 212d0353b83SRuslan Ermilov.Fn pthread_mutex_init "pthread_mutex_t *mutex" "const pthread_mutexattr_t *attr" 213d0353b83SRuslan Ermilov.Xc 214dfb9495bSTim VanderhoekInitialize a mutex with specified attributes. 215d0353b83SRuslan Ermilov.It Xo 216d0353b83SRuslan Ermilov.Ft int 217d0353b83SRuslan Ermilov.Fn pthread_mutex_lock "pthread_mutex_t *mutex" 218d0353b83SRuslan Ermilov.Xc 2190f7d6847SJulian ElischerLock a mutex and block until it becomes available. 220d0353b83SRuslan Ermilov.It Xo 221d0353b83SRuslan Ermilov.Ft int 222d0353b83SRuslan Ermilov.Fn pthread_mutex_trylock "pthread_mutex_t *mutex" 223d0353b83SRuslan Ermilov.Xc 2240f7d6847SJulian ElischerTry to lock a mutex, but don't block if the mutex is locked by another thread, 2250f7d6847SJulian Elischerincluding the current thread. 226d0353b83SRuslan Ermilov.It Xo 227d0353b83SRuslan Ermilov.Ft int 228d0353b83SRuslan Ermilov.Fn pthread_mutex_unlock "pthread_mutex_t *mutex" 229d0353b83SRuslan Ermilov.Xc 2300f7d6847SJulian ElischerUnlock a mutex. 2310f7d6847SJulian Elischer.El 2320f7d6847SJulian Elischer.Sh CONDITION VARIABLE ROUTINES 2330f7d6847SJulian Elischer.Bl -tag -width Er 234d0353b83SRuslan Ermilov.It Xo 235d0353b83SRuslan Ermilov.Ft int 236d0353b83SRuslan Ermilov.Fn pthread_condattr_init "pthread_condattr_t *attr" 237d0353b83SRuslan Ermilov.Xc 2380f7d6847SJulian ElischerInitialize a condition variable attributes object with default values. 239d0353b83SRuslan Ermilov.It Xo 240d0353b83SRuslan Ermilov.Ft int 241d0353b83SRuslan Ermilov.Fn pthread_condattr_destroy "pthread_condattr_t *attr" 242d0353b83SRuslan Ermilov.Xc 2430f7d6847SJulian ElischerDestroy a condition variable attributes object. 244d0353b83SRuslan Ermilov.It Xo 245d0353b83SRuslan Ermilov.Ft int 246d0353b83SRuslan Ermilov.Fn pthread_cond_broadcast "pthread_cond_t *cond" 247d0353b83SRuslan Ermilov.Xc 2480f7d6847SJulian ElischerUnblock all threads currently blocked on the specified condition variable. 249d0353b83SRuslan Ermilov.It Xo 250d0353b83SRuslan Ermilov.Ft int 251d0353b83SRuslan Ermilov.Fn pthread_cond_destroy "pthread_cond_t *cond" 252d0353b83SRuslan Ermilov.Xc 2530f7d6847SJulian ElischerDestroy a condition variable. 254d0353b83SRuslan Ermilov.It Xo 255d0353b83SRuslan Ermilov.Ft int 256d0353b83SRuslan Ermilov.Fn pthread_cond_init "pthread_cond_t *cond" "const pthread_condattr_t *attr" 257d0353b83SRuslan Ermilov.Xc 2580f7d6847SJulian ElischerInitialize a condition variable with specified attributes. 259d0353b83SRuslan Ermilov.It Xo 260d0353b83SRuslan Ermilov.Ft int 261d0353b83SRuslan Ermilov.Fn pthread_cond_signal "pthread_cond_t *cond" 262d0353b83SRuslan Ermilov.Xc 2630f7d6847SJulian ElischerUnblock at least one of the threads blocked on the specified condition variable. 264d0353b83SRuslan Ermilov.It Xo 265d0353b83SRuslan Ermilov.Ft int 266d0353b83SRuslan Ermilov.Fn pthread_cond_timedwait "pthread_cond_t *cond" "pthread_mutex_t *mutex" "const struct timespec *abstime" 267d0353b83SRuslan Ermilov.Xc 2680f7d6847SJulian ElischerWait no longer than the specified time for a condition and lock the specified mutex. 269d0353b83SRuslan Ermilov.It Xo 270d0353b83SRuslan Ermilov.Ft int 271d0353b83SRuslan Ermilov.Fn pthread_cond_wait "pthread_cond_t *" "pthread_mutex_t *mutex" 272d0353b83SRuslan Ermilov.Xc 2730f7d6847SJulian ElischerWait for a condition and lock the specified mutex. 2740f7d6847SJulian Elischer.El 275d4a76febSAlexander Langer.Sh READ/WRITE LOCK ROUTINES 276d4a76febSAlexander Langer.Bl -tag -width Er 277d0353b83SRuslan Ermilov.It Xo 278d0353b83SRuslan Ermilov.Ft int 279d0353b83SRuslan Ermilov.Fn pthread_rwlock_destroy "pthread_rwlock_t *lock" 280d0353b83SRuslan Ermilov.Xc 281d4a76febSAlexander LangerDestroy a read/write lock object. 282d0353b83SRuslan Ermilov.It Xo 283d0353b83SRuslan Ermilov.Ft int 284d0353b83SRuslan Ermilov.Fn pthread_rwlock_init "pthread_rwlock_t *lock" "const pthread_rwlockattr_t *attr" 285d0353b83SRuslan Ermilov.Xc 286d4a76febSAlexander LangerInitialize a read/write lock object. 287d0353b83SRuslan Ermilov.It Xo 288d0353b83SRuslan Ermilov.Ft int 289d0353b83SRuslan Ermilov.Fn pthread_rwlock_rdlock "pthread_rwlock_t *lock" 290d0353b83SRuslan Ermilov.Xc 291d4a76febSAlexander LangerLock a read/write lock for reading, blocking until the lock can be 292d4a76febSAlexander Langeracquired. 293d0353b83SRuslan Ermilov.It Xo 294d0353b83SRuslan Ermilov.Ft int 295d0353b83SRuslan Ermilov.Fn pthread_rwlock_tryrdlock "pthread_rwlock_t *lock" 296d0353b83SRuslan Ermilov.Xc 297d4a76febSAlexander LangerAttempt to lock a read/write lock for reading, without blocking if the 298d4a76febSAlexander Langerlock is unavailable. 299d0353b83SRuslan Ermilov.It Xo 300d0353b83SRuslan Ermilov.Ft int 301d0353b83SRuslan Ermilov.Fn pthread_rwlock_trywrlock "pthread_rwlock_t *lock" 302d0353b83SRuslan Ermilov.Xc 303d4a76febSAlexander LangerAttempt to lock a read/write lock for writing, without blocking if the 304d4a76febSAlexander Langerlock is unavailable. 305d0353b83SRuslan Ermilov.It Xo 306d0353b83SRuslan Ermilov.Ft int 307d0353b83SRuslan Ermilov.Fn pthread_rwlock_unlock "pthread_rwlock_t *lock" 308d0353b83SRuslan Ermilov.Xc 309d4a76febSAlexander LangerUnlock a read/write lock. 310d0353b83SRuslan Ermilov.It Xo 311d0353b83SRuslan Ermilov.Ft int 312d0353b83SRuslan Ermilov.Fn pthread_rwlock_wrlock "pthread_rwlock_t *lock" 313d0353b83SRuslan Ermilov.Xc 314d4a76febSAlexander LangerLock a read/write lock for writing, blocking until the lock can be 315d4a76febSAlexander Langeracquired. 316d0353b83SRuslan Ermilov.It Xo 317d0353b83SRuslan Ermilov.Ft int 318d0353b83SRuslan Ermilov.Fn pthread_rwlockattr_destroy "pthread_rwlockattr_t *attr" 319d0353b83SRuslan Ermilov.Xc 320d4a76febSAlexander LangerDestroy a read/write lock attribute object. 321d0353b83SRuslan Ermilov.It Xo 322d0353b83SRuslan Ermilov.Ft int 323c70db3ffSBruce Evans.Fn pthread_rwlockattr_getpshared "const pthread_rwlockattr_t *attr" "int *pshared" 324d0353b83SRuslan Ermilov.Xc 325d4a76febSAlexander LangerRetrieve the process shared setting for the read/write lock attribute 326d4a76febSAlexander Langerobject. 327d0353b83SRuslan Ermilov.It Xo 328d0353b83SRuslan Ermilov.Ft int 329d0353b83SRuslan Ermilov.Fn pthread_rwlockattr_init "pthread_rwlockattr_t *attr" 330d0353b83SRuslan Ermilov.Xc 331d4a76febSAlexander LangerInitialize a read/write lock attribute object. 332d0353b83SRuslan Ermilov.It Xo 333d0353b83SRuslan Ermilov.Ft int 334c70db3ffSBruce Evans.Fn pthread_rwlockattr_setpshared "pthread_rwlockattr_t *attr" "int pshared" 335d0353b83SRuslan Ermilov.Xc 336d4a76febSAlexander LangerSet the process shared setting for the read/write lock attribute object. 337d4a76febSAlexander Langer.El 3380f7d6847SJulian Elischer.Sh PER-THREAD CONTEXT ROUTINES 3390f7d6847SJulian Elischer.Bl -tag -width Er 340d0353b83SRuslan Ermilov.It Xo 341d0353b83SRuslan Ermilov.Ft int 342d0353b83SRuslan Ermilov.Fn pthread_key_create "pthread_key_t *key" "void (*routine)(void *)" 343d0353b83SRuslan Ermilov.Xc 3440f7d6847SJulian ElischerCreate a thread-specific data key. 345d0353b83SRuslan Ermilov.It Xo 346d0353b83SRuslan Ermilov.Ft int 347d0353b83SRuslan Ermilov.Fn pthread_key_delete "pthread_key_t key" 348d0353b83SRuslan Ermilov.Xc 3490f7d6847SJulian ElischerDelete a thread-specific data key. 350d0353b83SRuslan Ermilov.It Xo 351d0353b83SRuslan Ermilov.Ft "void *" 352c70db3ffSBruce Evans.Fn pthread_getspecific "pthread_key_t key" 353d0353b83SRuslan Ermilov.Xc 3540f7d6847SJulian ElischerGet the thread-specific value for the specified key. 355d0353b83SRuslan Ermilov.It Xo 356d0353b83SRuslan Ermilov.Ft int 357d0353b83SRuslan Ermilov.Fn pthread_setspecific "pthread_key_t key" "const void *value_ptr" 358d0353b83SRuslan Ermilov.Xc 3590f7d6847SJulian ElischerSet the thread-specific value for the specified key. 3600f7d6847SJulian Elischer.El 3610f7d6847SJulian Elischer.Sh CLEANUP ROUTINES 3620f7d6847SJulian Elischer.Bl -tag -width Er 363d0353b83SRuslan Ermilov.It Xo 364d0353b83SRuslan Ermilov.Ft void 365d0353b83SRuslan Ermilov.Fn pthread_cleanup_pop "int execute" 366d0353b83SRuslan Ermilov.Xc 3670f7d6847SJulian ElischerRemove the routine at the top of the calling thread's cancellation cleanup 3680f7d6847SJulian Elischerstack and optionally invoke it. 369d0353b83SRuslan Ermilov.It Xo 370d0353b83SRuslan Ermilov.Ft void 371d0353b83SRuslan Ermilov.Fn pthread_cleanup_push "void (*routine)(void *)" "void *routine_arg" 372d0353b83SRuslan Ermilov.Xc 3730f7d6847SJulian ElischerPush the specified cancellation cleanup handler onto the calling thread's 3740f7d6847SJulian Elischercancellation stack. 3750f7d6847SJulian Elischer.El 3760f7d6847SJulian Elischer.Sh INSTALLATION 377b5c508fbSRuslan ErmilovThe current 378b5c508fbSRuslan Ermilov.Fx 379b5c508fbSRuslan ErmilovPOSIX thread implementation is built in the library 3800f7d6847SJulian Elischer.Fa libc_r 3810f7d6847SJulian Elischerwhich contains both thread-safe libc functions and the thread functions. 3820f7d6847SJulian ElischerThis library replaces 3830f7d6847SJulian Elischer.Fa libc 3840f7d6847SJulian Elischerfor threaded applications. 3850f7d6847SJulian Elischer.Pp 3860f7d6847SJulian ElischerBy default, 3870f7d6847SJulian Elischer.Fa libc_r 388106115b3SSteve Priceis built as part of a 'make world'. To disable the build of 3890f7d6847SJulian Elischer.Fa libc_r 390106115b3SSteve Priceyou must supply the '-DNOLIBC_R' option to 391106115b3SSteve Price.Xr make 1 . 392087ee430SJohn Birrell.Pp 393b5c508fbSRuslan ErmilovA 394b5c508fbSRuslan Ermilov.Fx 395b5c508fbSRuslan Ermilovspecific option has been added to gcc to make linking 396087ee430SJohn Birrellthreaded processes simple. 397087ee430SJohn Birrell.Fa gcc -pthread 398087ee430SJohn Birrelllinks a threaded process against 399087ee430SJohn Birrell.Fa libc_r 400087ee430SJohn Birrellinstead of 401087ee430SJohn Birrell.Fa libc . 402997d90beSBill Swingle.Sh SEE ALSO 4035521ff5aSRuslan Ermilov.Xr pthread_cleanup_pop 3 , 4045521ff5aSRuslan Ermilov.Xr pthread_cleanup_push 3 , 405997d90beSBill Swingle.Xr pthread_cond_broadcast 3 , 406997d90beSBill Swingle.Xr pthread_cond_destroy 3 , 407997d90beSBill Swingle.Xr pthread_cond_init 3 , 408997d90beSBill Swingle.Xr pthread_cond_signal 3 , 409997d90beSBill Swingle.Xr pthread_cond_timedwait 3 , 410997d90beSBill Swingle.Xr pthread_cond_wait 3 , 4115521ff5aSRuslan Ermilov.Xr pthread_create 3 , 4125521ff5aSRuslan Ermilov.Xr pthread_detach 3 , 4135521ff5aSRuslan Ermilov.Xr pthread_equal 3 , 4145521ff5aSRuslan Ermilov.Xr pthread_exit 3 , 4155521ff5aSRuslan Ermilov.Xr pthread_getspecific 3 , 4165521ff5aSRuslan Ermilov.Xr pthread_join 3 , 4175521ff5aSRuslan Ermilov.Xr pthread_key_delete 3 , 4185521ff5aSRuslan Ermilov.Xr pthread_mutex_destroy 3 , 4195521ff5aSRuslan Ermilov.Xr pthread_mutex_init 3 , 4205521ff5aSRuslan Ermilov.Xr pthread_mutex_lock 3 , 4215521ff5aSRuslan Ermilov.Xr pthread_mutex_trylock 3 , 4225521ff5aSRuslan Ermilov.Xr pthread_mutex_unlock 3 , 4235521ff5aSRuslan Ermilov.Xr pthread_once 3 , 4245521ff5aSRuslan Ermilov.Xr pthread_rwlockattr_destroy 3 , 4255521ff5aSRuslan Ermilov.Xr pthread_rwlockattr_getpshared 3 , 4265521ff5aSRuslan Ermilov.Xr pthread_rwlockattr_init 3 , 4275521ff5aSRuslan Ermilov.Xr pthread_rwlockattr_setpshared 3 , 428997d90beSBill Swingle.Xr pthread_rwlock_destroy 3 , 429997d90beSBill Swingle.Xr pthread_rwlock_init 3 , 430997d90beSBill Swingle.Xr pthread_rwlock_rdlock 3 , 431997d90beSBill Swingle.Xr pthread_rwlock_unlock 3 , 432997d90beSBill Swingle.Xr pthread_rwlock_wrlock 3 , 4335521ff5aSRuslan Ermilov.Xr pthread_self 3 , 4345521ff5aSRuslan Ermilov.Xr pthread_setspecific 3 4350f7d6847SJulian Elischer.Sh STANDARDS 4360f7d6847SJulian ElischerThe functions in 4370f7d6847SJulian Elischer.Fa libc_r 4380f7d6847SJulian Elischerwith the 4390f7d6847SJulian Elischer.Fa pthread_ 440efc0456fSAlexander Langerprefix and not 4410f7d6847SJulian Elischer.Fa _np 442d4a76febSAlexander Langersuffix or 443d4a76febSAlexander Langer.Fa pthread_rwlock 4443c233756SRuslan Ermilovprefix conform to 4453c233756SRuslan Ermilov.St -p1003.1-96 . 4460f7d6847SJulian Elischer.Pp 4470f7d6847SJulian ElischerThe functions in libc_r with the 4480f7d6847SJulian Elischer.Fa pthread_ 4490f7d6847SJulian Elischerprefix and 4500f7d6847SJulian Elischer.Fa _np 4510f7d6847SJulian Elischersuffix are non-portable extensions to POSIX threads. 452d4a76febSAlexander Langer.Pp 453d4a76febSAlexander LangerThe functions in libc_r with the 454d4a76febSAlexander Langer.Fa pthread_rwlock 4553c233756SRuslan Ermilovprefix are extensions created by The Open Group as part of the 4563c233756SRuslan Ermilov.St -susv2 . 457