1996-08-20 08:22:01 +00:00
|
|
|
.\" Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>.
|
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\" 3. All advertising materials mentioning features or use of this software
|
|
|
|
.\" must display the following acknowledgement:
|
|
|
|
.\" This product includes software developed by John Birrell.
|
|
|
|
.\" 4. Neither the name of the author nor the names of any co-contributors
|
|
|
|
.\" may be used to endorse or promote products derived from this software
|
|
|
|
.\" without specific prior written permission.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\"
|
1999-08-28 00:22:10 +00:00
|
|
|
.\" $FreeBSD$
|
1997-03-07 03:28:23 +00:00
|
|
|
.\"
|
2004-01-15 17:58:26 +00:00
|
|
|
.Dd January 15, 2004
|
1996-08-20 08:22:01 +00:00
|
|
|
.Dt PTHREAD 3
|
2001-07-10 15:31:11 +00:00
|
|
|
.Os
|
1996-08-20 08:22:01 +00:00
|
|
|
.Sh NAME
|
|
|
|
.Nm pthread
|
|
|
|
.Nd POSIX thread functions
|
2004-04-08 23:04:54 +00:00
|
|
|
.Sh LIBRARY
|
|
|
|
.Lb libpthread
|
|
|
|
.Lb libthr
|
|
|
|
.Lb libc_r
|
2001-02-06 01:31:04 +00:00
|
|
|
.Sh SYNOPSIS
|
2001-10-01 16:09:29 +00:00
|
|
|
.In pthread.h
|
1996-08-20 08:22:01 +00:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
POSIX threads are a set of functions that support applications with
|
|
|
|
requirements for multiple flows of control, called
|
2004-01-15 11:15:27 +00:00
|
|
|
.Em threads ,
|
2000-03-01 14:50:24 +00:00
|
|
|
within a process.
|
|
|
|
Multithreading is used to improve the performance of a
|
1996-08-20 08:22:01 +00:00
|
|
|
program.
|
|
|
|
.Pp
|
|
|
|
The POSIX thread functions are summarized in this section in the following
|
|
|
|
groups:
|
2004-01-15 11:15:27 +00:00
|
|
|
.Pp
|
|
|
|
.Bl -bullet -offset indent -compact
|
1996-08-20 08:22:01 +00:00
|
|
|
.It
|
1998-09-12 13:53:58 +00:00
|
|
|
Thread Routines
|
1996-08-20 08:22:01 +00:00
|
|
|
.It
|
|
|
|
Attribute Object Routines
|
|
|
|
.It
|
|
|
|
Mutex Routines
|
|
|
|
.It
|
|
|
|
Condition Variable Routines
|
|
|
|
.It
|
1998-09-12 13:53:58 +00:00
|
|
|
Read/Write Lock Routines
|
|
|
|
.It
|
1996-08-20 08:22:01 +00:00
|
|
|
Per-Thread Context Routines
|
|
|
|
.It
|
|
|
|
Cleanup Routines
|
|
|
|
.El
|
2004-01-15 11:15:27 +00:00
|
|
|
.Ss Thread Routines
|
|
|
|
.Bl -tag -width indent
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
2004-01-15 11:15:27 +00:00
|
|
|
.Fo pthread_create
|
|
|
|
.Fa "pthread_t *thread" "const pthread_attr_t *attr"
|
|
|
|
.Fa "void *\*[lp]*start_routine\*[rp]\*[lp]void *\*[rp]" "void *arg"
|
|
|
|
.Fc
|
2001-02-01 16:38:02 +00:00
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Creates a new thread of execution.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
2002-03-11 10:45:18 +00:00
|
|
|
.Fn pthread_cancel "pthread_t thread"
|
|
|
|
.Xc
|
|
|
|
Cancels execution of a thread.
|
|
|
|
.It Xo
|
|
|
|
.Ft int
|
2001-02-01 16:38:02 +00:00
|
|
|
.Fn pthread_detach "pthread_t thread"
|
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Marks a thread for deletion.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_equal "pthread_t t1" "pthread_t t2"
|
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Compares two thread IDs.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft void
|
|
|
|
.Fn pthread_exit "void *value_ptr"
|
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Terminates the calling thread.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_join "pthread_t thread" "void **value_ptr"
|
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Causes the calling thread to wait for the termination of the specified thread.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
2002-03-11 10:45:18 +00:00
|
|
|
.Fn pthread_kill "pthread_t thread" "int sig"
|
2001-02-01 16:38:02 +00:00
|
|
|
.Xc
|
2002-03-11 10:45:18 +00:00
|
|
|
Delivers a signal to a specified thread.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
2004-01-15 11:15:27 +00:00
|
|
|
.Fn pthread_once "pthread_once_t *once_control" "void \*[lp]*init_routine\*[rp]\*[lp]void\*[rp]"
|
2001-02-01 16:38:02 +00:00
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Calls an initialization routine once.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft pthread_t
|
|
|
|
.Fn pthread_self void
|
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Returns the thread ID of the calling thread.
|
2002-03-11 10:45:18 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_setcancelstate "int state" "int *oldstate"
|
|
|
|
.Xc
|
|
|
|
Sets the current thread's cancelability state.
|
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_setcanceltype "int type" "int *oldtype"
|
|
|
|
.Xc
|
|
|
|
Sets the current thread's cancelability type.
|
|
|
|
.It Xo
|
|
|
|
.Ft void
|
|
|
|
.Fn pthread_testcancel void
|
|
|
|
.Xc
|
|
|
|
Creates a cancellation point in the calling thread.
|
|
|
|
.It Xo
|
|
|
|
.Ft void
|
|
|
|
.Fn pthread_yield void
|
|
|
|
.Xc
|
|
|
|
Allows the scheduler to run another thread instead of the current one.
|
1996-08-20 08:22:01 +00:00
|
|
|
.El
|
2004-01-15 11:15:27 +00:00
|
|
|
.Ss Attribute Object Routines
|
|
|
|
.Bl -tag -width indent
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_attr_destroy "pthread_attr_t *attr"
|
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Destroy a thread attributes object.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
2004-01-15 11:15:27 +00:00
|
|
|
.Fo pthread_attr_getinheritsched
|
|
|
|
.Fa "const pthread_attr_t *attr" "int *inheritsched"
|
|
|
|
.Fc
|
2001-02-01 16:38:02 +00:00
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Get the inherit scheduling attribute from a thread attributes object.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
2004-01-15 11:15:27 +00:00
|
|
|
.Fo pthread_attr_getschedparam
|
|
|
|
.Fa "const pthread_attr_t *attr" "struct sched_param *param"
|
|
|
|
.Fc
|
2001-02-01 16:38:02 +00:00
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Get the scheduling parameter attribute from a thread attributes object.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
2001-02-06 01:31:04 +00:00
|
|
|
.Fn pthread_attr_getschedpolicy "const pthread_attr_t *attr" "int *policy"
|
2001-02-01 16:38:02 +00:00
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Get the scheduling policy attribute from a thread attributes object.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
2001-02-06 01:31:04 +00:00
|
|
|
.Fn pthread_attr_getscope "const pthread_attr_t *attr" "int *contentionscope"
|
2001-02-01 16:38:02 +00:00
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Get the contention scope attribute from a thread attributes object.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
2001-02-06 01:31:04 +00:00
|
|
|
.Fn pthread_attr_getstacksize "const pthread_attr_t *attr" "size_t *stacksize"
|
2001-02-01 16:38:02 +00:00
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Get the stack size attribute from a thread attributes object.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
2001-02-06 01:31:04 +00:00
|
|
|
.Fn pthread_attr_getstackaddr "const pthread_attr_t *attr" "void **stackaddr"
|
2001-02-01 16:38:02 +00:00
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Get the stack address attribute from a thread attributes object.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
2001-02-06 01:31:04 +00:00
|
|
|
.Fn pthread_attr_getdetachstate "const pthread_attr_t *attr" "int *detachstate"
|
2001-02-01 16:38:02 +00:00
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Get the detach state attribute from a thread attributes object.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_attr_init "pthread_attr_t *attr"
|
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Initialize a thread attributes object with default values.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_attr_setinheritsched "pthread_attr_t *attr" "int inheritsched"
|
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Set the inherit scheduling attribute in a thread attributes object.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
2004-01-15 11:15:27 +00:00
|
|
|
.Fo pthread_attr_setschedparam
|
|
|
|
.Fa "pthread_attr_t *attr" "const struct sched_param *param"
|
|
|
|
.Fc
|
2001-02-01 16:38:02 +00:00
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Set the scheduling parameter attribute in a thread attributes object.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_attr_setschedpolicy "pthread_attr_t *attr" "int policy"
|
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Set the scheduling policy attribute in a thread attributes object.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_attr_setscope "pthread_attr_t *attr" "int contentionscope"
|
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Set the contention scope attribute in a thread attributes object.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_attr_setstacksize "pthread_attr_t *attr" "size_t stacksize"
|
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Set the stack size attribute in a thread attributes object.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_attr_setstackaddr "pthread_attr_t *attr" "void *stackaddr"
|
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Set the stack address attribute in a thread attributes object.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_attr_setdetachstate "pthread_attr_t *attr" "int detachstate"
|
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Set the detach state in a thread attributes object.
|
|
|
|
.El
|
2004-01-15 11:15:27 +00:00
|
|
|
.Ss Mutex Routines
|
|
|
|
.Bl -tag -width indent
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_mutexattr_destroy "pthread_mutexattr_t *attr"
|
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Destroy a mutex attributes object.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
2002-03-11 10:45:18 +00:00
|
|
|
.Fn pthread_mutexattr_getprioceiling "pthread_mutexattr_t *attr" "int *ceiling"
|
|
|
|
.Xc
|
|
|
|
Obtain priority ceiling attribute of mutex attribute object.
|
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_mutexattr_getprotocol "pthread_mutexattr_t *attr" "int *protocol"
|
|
|
|
.Xc
|
|
|
|
Obtain protocol attribute of mutex attribute object.
|
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_mutexattr_gettype "pthread_mutexattr_t *attr" "int *type"
|
|
|
|
.Xc
|
|
|
|
Obtain the mutex type attribute in the specified mutex attributes object.
|
|
|
|
.It Xo
|
|
|
|
.Ft int
|
2001-02-01 16:38:02 +00:00
|
|
|
.Fn pthread_mutexattr_init "pthread_mutexattr_t *attr"
|
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Initialize a mutex attributes object with default values.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
2002-03-11 10:45:18 +00:00
|
|
|
.Fn pthread_mutexattr_setprioceiling "pthread_mutexattr_t *attr" "int ceiling"
|
|
|
|
.Xc
|
|
|
|
Set priority ceiling attribute of mutex attribute object.
|
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_mutexattr_setprotocol "pthread_mutexattr_t *attr" "int protocol"
|
|
|
|
.Xc
|
|
|
|
Set protocol attribute of mutex attribute object.
|
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_mutexattr_settype "pthread_mutexattr_t *attr" "int type"
|
|
|
|
.Xc
|
|
|
|
Set the mutex type attribute that is used when a mutex is created.
|
|
|
|
.It Xo
|
|
|
|
.Ft int
|
2001-02-01 16:38:02 +00:00
|
|
|
.Fn pthread_mutex_destroy "pthread_mutex_t *mutex"
|
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Destroy a mutex.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
2004-01-15 11:15:27 +00:00
|
|
|
.Fo pthread_mutex_init
|
|
|
|
.Fa "pthread_mutex_t *mutex" "const pthread_mutexattr_t *attr"
|
|
|
|
.Fc
|
2001-02-01 16:38:02 +00:00
|
|
|
.Xc
|
1997-12-25 09:36:42 +00:00
|
|
|
Initialize a mutex with specified attributes.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_mutex_lock "pthread_mutex_t *mutex"
|
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Lock a mutex and block until it becomes available.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
2004-01-15 11:15:27 +00:00
|
|
|
.Fo pthread_mutex_timedlock
|
|
|
|
.Fa "pthread_mutex_t *mutex" "const struct timespec *abstime"
|
|
|
|
.Fc
|
2003-12-30 08:44:55 +00:00
|
|
|
.Xc
|
|
|
|
Lock a mutex and block until it becomes available or until the timeout expires.
|
|
|
|
.It Xo
|
|
|
|
.Ft int
|
2001-02-01 16:38:02 +00:00
|
|
|
.Fn pthread_mutex_trylock "pthread_mutex_t *mutex"
|
|
|
|
.Xc
|
2005-02-13 22:25:33 +00:00
|
|
|
Try to lock a mutex, but do not block if the mutex is locked by another thread,
|
1996-08-20 08:22:01 +00:00
|
|
|
including the current thread.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_mutex_unlock "pthread_mutex_t *mutex"
|
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Unlock a mutex.
|
|
|
|
.El
|
2004-01-15 11:15:27 +00:00
|
|
|
.Ss Condition Variable Routines
|
|
|
|
.Bl -tag -width indent
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
2002-03-11 10:45:18 +00:00
|
|
|
.Fn pthread_condattr_destroy "pthread_condattr_t *attr"
|
2001-02-01 16:38:02 +00:00
|
|
|
.Xc
|
2002-03-11 10:45:18 +00:00
|
|
|
Destroy a condition variable attributes object.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
2002-03-11 10:45:18 +00:00
|
|
|
.Fn pthread_condattr_init "pthread_condattr_t *attr"
|
2001-02-01 16:38:02 +00:00
|
|
|
.Xc
|
2002-03-11 10:45:18 +00:00
|
|
|
Initialize a condition variable attributes object with default values.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_cond_broadcast "pthread_cond_t *cond"
|
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Unblock all threads currently blocked on the specified condition variable.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_cond_destroy "pthread_cond_t *cond"
|
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Destroy a condition variable.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_cond_init "pthread_cond_t *cond" "const pthread_condattr_t *attr"
|
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Initialize a condition variable with specified attributes.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_cond_signal "pthread_cond_t *cond"
|
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Unblock at least one of the threads blocked on the specified condition variable.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
2004-01-15 11:15:27 +00:00
|
|
|
.Fo pthread_cond_timedwait
|
|
|
|
.Fa "pthread_cond_t *cond" "pthread_mutex_t *mutex"
|
|
|
|
.Fa "const struct timespec *abstime"
|
|
|
|
.Fc
|
2001-02-01 16:38:02 +00:00
|
|
|
.Xc
|
2004-01-15 11:15:27 +00:00
|
|
|
Wait no longer than the specified time for a condition
|
|
|
|
and lock the specified mutex.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_cond_wait "pthread_cond_t *" "pthread_mutex_t *mutex"
|
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Wait for a condition and lock the specified mutex.
|
|
|
|
.El
|
2004-01-15 11:15:27 +00:00
|
|
|
.Ss Read/Write Lock Routines
|
|
|
|
.Bl -tag -width indent
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_rwlock_destroy "pthread_rwlock_t *lock"
|
|
|
|
.Xc
|
1998-09-12 13:53:58 +00:00
|
|
|
Destroy a read/write lock object.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
2004-01-15 11:15:27 +00:00
|
|
|
.Fo pthread_rwlock_init
|
|
|
|
.Fa "pthread_rwlock_t *lock" "const pthread_rwlockattr_t *attr"
|
|
|
|
.Fc
|
2001-02-01 16:38:02 +00:00
|
|
|
.Xc
|
1998-09-12 13:53:58 +00:00
|
|
|
Initialize a read/write lock object.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_rwlock_rdlock "pthread_rwlock_t *lock"
|
|
|
|
.Xc
|
1998-09-12 13:53:58 +00:00
|
|
|
Lock a read/write lock for reading, blocking until the lock can be
|
|
|
|
acquired.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_rwlock_tryrdlock "pthread_rwlock_t *lock"
|
|
|
|
.Xc
|
1998-09-12 13:53:58 +00:00
|
|
|
Attempt to lock a read/write lock for reading, without blocking if the
|
|
|
|
lock is unavailable.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_rwlock_trywrlock "pthread_rwlock_t *lock"
|
|
|
|
.Xc
|
1998-09-12 13:53:58 +00:00
|
|
|
Attempt to lock a read/write lock for writing, without blocking if the
|
|
|
|
lock is unavailable.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_rwlock_unlock "pthread_rwlock_t *lock"
|
|
|
|
.Xc
|
1998-09-12 13:53:58 +00:00
|
|
|
Unlock a read/write lock.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_rwlock_wrlock "pthread_rwlock_t *lock"
|
|
|
|
.Xc
|
1998-09-12 13:53:58 +00:00
|
|
|
Lock a read/write lock for writing, blocking until the lock can be
|
|
|
|
acquired.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_rwlockattr_destroy "pthread_rwlockattr_t *attr"
|
|
|
|
.Xc
|
1998-09-12 13:53:58 +00:00
|
|
|
Destroy a read/write lock attribute object.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
2004-01-15 11:15:27 +00:00
|
|
|
.Fo pthread_rwlockattr_getpshared
|
|
|
|
.Fa "const pthread_rwlockattr_t *attr" "int *pshared"
|
|
|
|
.Fc
|
2001-02-01 16:38:02 +00:00
|
|
|
.Xc
|
1998-09-12 13:53:58 +00:00
|
|
|
Retrieve the process shared setting for the read/write lock attribute
|
|
|
|
object.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_rwlockattr_init "pthread_rwlockattr_t *attr"
|
|
|
|
.Xc
|
1998-09-12 13:53:58 +00:00
|
|
|
Initialize a read/write lock attribute object.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
2001-02-06 01:31:04 +00:00
|
|
|
.Fn pthread_rwlockattr_setpshared "pthread_rwlockattr_t *attr" "int pshared"
|
2001-02-01 16:38:02 +00:00
|
|
|
.Xc
|
1998-09-12 13:53:58 +00:00
|
|
|
Set the process shared setting for the read/write lock attribute object.
|
|
|
|
.El
|
2004-01-15 11:15:27 +00:00
|
|
|
.Ss Per-Thread Context Routines
|
|
|
|
.Bl -tag -width indent
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
2004-01-15 11:15:27 +00:00
|
|
|
.Fn pthread_key_create "pthread_key_t *key" "void \*[lp]*routine\*[rp]\*[lp]void *\*[rp]"
|
2001-02-01 16:38:02 +00:00
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Create a thread-specific data key.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_key_delete "pthread_key_t key"
|
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Delete a thread-specific data key.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft "void *"
|
2001-02-06 01:31:04 +00:00
|
|
|
.Fn pthread_getspecific "pthread_key_t key"
|
2001-02-01 16:38:02 +00:00
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Get the thread-specific value for the specified key.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_setspecific "pthread_key_t key" "const void *value_ptr"
|
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Set the thread-specific value for the specified key.
|
|
|
|
.El
|
2004-01-15 11:15:27 +00:00
|
|
|
.Ss Cleanup Routines
|
|
|
|
.Bl -tag -width indent
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
2005-05-18 16:23:11 +00:00
|
|
|
.Ft int
|
|
|
|
.Fo pthread_atfork
|
|
|
|
.Fa "void \*[lp]*prepare\*[rp]\*[lp]void\*[rp]"
|
|
|
|
.Fa "void \*[lp]*parent\*[rp]\*[lp]void\*[rp]"
|
|
|
|
.Fa "void \*[lp]*child\*[rp]\*[lp]void\*[rp]"
|
|
|
|
.Fc
|
|
|
|
.Xc
|
|
|
|
Register fork handlers
|
|
|
|
.It Xo
|
2001-02-01 16:38:02 +00:00
|
|
|
.Ft void
|
|
|
|
.Fn pthread_cleanup_pop "int execute"
|
|
|
|
.Xc
|
1996-08-20 08:22:01 +00:00
|
|
|
Remove the routine at the top of the calling thread's cancellation cleanup
|
|
|
|
stack and optionally invoke it.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Xo
|
|
|
|
.Ft void
|
2004-01-15 11:15:27 +00:00
|
|
|
.Fn pthread_cleanup_push "void \*[lp]*routine\*[rp]\*[lp]void *\*[rp]" "void *routine_arg"
|
2001-02-01 16:38:02 +00:00
|
|
|
.Xc
|
2001-07-14 19:41:16 +00:00
|
|
|
Push the specified cancellation cleanup handler onto the calling thread's
|
1996-08-20 08:22:01 +00:00
|
|
|
cancellation stack.
|
|
|
|
.El
|
|
|
|
.Sh INSTALLATION
|
2000-11-14 11:20:58 +00:00
|
|
|
The current
|
|
|
|
.Fx
|
2004-01-15 17:58:26 +00:00
|
|
|
POSIX thread implementation is built in three libraries,
|
|
|
|
.Lb libc_r ,
|
|
|
|
.Lb libpthread ,
|
|
|
|
and
|
|
|
|
.Lb libthr .
|
|
|
|
They contain both thread-safe versions of
|
|
|
|
.Lb libc
|
|
|
|
functions and the thread functions.
|
|
|
|
Threaded applications are linked with one of these libraries.
|
2000-02-18 02:10:38 +00:00
|
|
|
.Sh SEE ALSO
|
2005-05-18 16:23:11 +00:00
|
|
|
.Xr pthread_atfork 3 ,
|
2001-07-06 16:46:48 +00:00
|
|
|
.Xr pthread_cleanup_pop 3 ,
|
|
|
|
.Xr pthread_cleanup_push 3 ,
|
2002-12-13 16:53:51 +00:00
|
|
|
.Xr pthread_condattr_destroy 3 ,
|
|
|
|
.Xr pthread_condattr_init 3 ,
|
2001-07-06 16:46:48 +00:00
|
|
|
.Xr pthread_cond_broadcast 3 ,
|
|
|
|
.Xr pthread_cond_destroy 3 ,
|
|
|
|
.Xr pthread_cond_init 3 ,
|
|
|
|
.Xr pthread_cond_signal 3 ,
|
|
|
|
.Xr pthread_cond_timedwait 3 ,
|
|
|
|
.Xr pthread_cond_wait 3 ,
|
2000-02-18 02:10:38 +00:00
|
|
|
.Xr pthread_create 3 ,
|
|
|
|
.Xr pthread_detach 3 ,
|
|
|
|
.Xr pthread_equal 3 ,
|
|
|
|
.Xr pthread_exit 3 ,
|
2001-07-06 16:46:48 +00:00
|
|
|
.Xr pthread_getspecific 3 ,
|
2000-02-18 02:10:38 +00:00
|
|
|
.Xr pthread_join 3 ,
|
2001-07-06 16:46:48 +00:00
|
|
|
.Xr pthread_key_delete 3 ,
|
2002-03-11 10:45:18 +00:00
|
|
|
.Xr pthread_kill 3 ,
|
|
|
|
.Xr pthread_mutexattr_destroy 3 ,
|
|
|
|
.Xr pthread_mutexattr_getprioceiling 3 ,
|
|
|
|
.Xr pthread_mutexattr_getprotocol 3 ,
|
|
|
|
.Xr pthread_mutexattr_gettype 3 ,
|
|
|
|
.Xr pthread_mutexattr_init 3 ,
|
|
|
|
.Xr pthread_mutexattr_setprioceiling 3 ,
|
|
|
|
.Xr pthread_mutexattr_setprotocol 3 ,
|
|
|
|
.Xr pthread_mutexattr_settype 3 ,
|
2002-12-13 16:53:51 +00:00
|
|
|
.Xr pthread_mutex_destroy 3 ,
|
|
|
|
.Xr pthread_mutex_init 3 ,
|
|
|
|
.Xr pthread_mutex_lock 3 ,
|
|
|
|
.Xr pthread_mutex_trylock 3 ,
|
|
|
|
.Xr pthread_mutex_unlock 3 ,
|
2001-07-06 16:46:48 +00:00
|
|
|
.Xr pthread_once 3 ,
|
|
|
|
.Xr pthread_rwlockattr_destroy 3 ,
|
|
|
|
.Xr pthread_rwlockattr_getpshared 3 ,
|
|
|
|
.Xr pthread_rwlockattr_init 3 ,
|
|
|
|
.Xr pthread_rwlockattr_setpshared 3 ,
|
2000-02-18 02:10:38 +00:00
|
|
|
.Xr pthread_rwlock_destroy 3 ,
|
|
|
|
.Xr pthread_rwlock_init 3 ,
|
|
|
|
.Xr pthread_rwlock_rdlock 3 ,
|
|
|
|
.Xr pthread_rwlock_unlock 3 ,
|
|
|
|
.Xr pthread_rwlock_wrlock 3 ,
|
2001-07-06 16:46:48 +00:00
|
|
|
.Xr pthread_self 3 ,
|
2002-03-11 10:45:18 +00:00
|
|
|
.Xr pthread_setcancelstate 3 ,
|
|
|
|
.Xr pthread_setcanceltype 3 ,
|
|
|
|
.Xr pthread_setspecific 3 ,
|
|
|
|
.Xr pthread_testcancel 3
|
1996-08-20 08:22:01 +00:00
|
|
|
.Sh STANDARDS
|
2004-01-15 17:58:26 +00:00
|
|
|
The functions with the
|
|
|
|
.Nm pthread_
|
1998-01-02 19:19:50 +00:00
|
|
|
prefix and not
|
2004-01-15 17:58:26 +00:00
|
|
|
.Nm _np
|
1998-09-12 13:53:58 +00:00
|
|
|
suffix or
|
2004-01-15 17:58:26 +00:00
|
|
|
.Nm pthread_rwlock
|
2001-02-26 16:02:53 +00:00
|
|
|
prefix conform to
|
|
|
|
.St -p1003.1-96 .
|
1996-08-20 08:22:01 +00:00
|
|
|
.Pp
|
2004-01-15 17:58:26 +00:00
|
|
|
The functions with the
|
|
|
|
.Nm pthread_
|
1996-08-20 08:22:01 +00:00
|
|
|
prefix and
|
2004-01-15 17:58:26 +00:00
|
|
|
.Nm _np
|
1996-08-20 08:22:01 +00:00
|
|
|
suffix are non-portable extensions to POSIX threads.
|
1998-09-12 13:53:58 +00:00
|
|
|
.Pp
|
2004-01-15 17:58:26 +00:00
|
|
|
The functions with the
|
|
|
|
.Nm pthread_rwlock
|
2001-02-26 16:02:53 +00:00
|
|
|
prefix are extensions created by The Open Group as part of the
|
|
|
|
.St -susv2 .
|