
Name Space
Threads Types
| Description | Register functions to be called during fork() execution |
| Errors | ENOMEM |
| Notes |
.
Threads Attributes
All threads attributes are set in a thread attributes object bya function of the form:
| Description and Value(s) | |
| size_t stacksize | The thread's stack size. >= PTHREAD_STACK_MIN |
| void *stackaddr | The thread's stack address. For example, void *stack |
| size_t guardsize | The thread's stack guard size. The default size is PAGESIZE bytes. |
| int detachstate | The thread's detach state: PTHREAD_CREATE_DETACHED,PTHREAD_CREATE_JOINABLE |
| int contentionscope | The thread's scope. PTHREAD_SCOPE_SYSTEM, PTHREAD_SCOPE_PROCESS |
| int inheritsched | The thread's scheduling inheritence PTHREAD_INHERIT_SCHED,PTHREAD_EXPLICIT_SCHED |
| int schedpolicy | The thread's scheduling policy. SCHED_FIFO, SCHED_RR, SCHED_OTHER |
| struct sched_param schedparam | The thread's scheduling parameters. See POSIX.1 Section 13 |
pthread_attr_init
| Synopsis | |
| Description | Initialize a thread attributes object. |
| Errors | ENOMEM |
pthread_attr_destroy
| Synopsis | |
| Description | Destroy a thread attributes object |
| Errors | None |
The other attribute related functions are listed below:
Thread Management
| Description | Create a new thread of execution |
| Errors | EAGAIN, EINVAL |
| Notes | Maximum number of PTHREADS_THREADS_MAX per process |
pthread_detach
| Synopsis | |
| Description | Set the detachstate of the specified thread to PTHREAD_CREATE_DETACHED |
| Errors | EINVAL,ESRCH |
pthread_safe
| Synopsis | |
| Description | Return the thread ID of the calling thread |
| Errors | None |
pthread_equal
| Synopsis | |
| Description | Compare two thread Ids for equality |
| Errors | None |
pthread_exit
| Synopsis | |
| Description | Terminate the calling thread |
| Errors | None |
pthread_join
| Synopsis | |
| Description | Synchronize with the termination of a thread |
| Errors | EINVAL,ESRCH,EDEADLK |
| Notes | This function is a cancellation point |
pthread_getschedparam
| Synopsis | |
| Description | Get the scheduling policy and parameters of the specified thread |
| Errors | ENOSYS,ESRCH |
| Notes | Dependent on support of _XOPEN_REALTIME_THREADS |
pthread_setschedparam
| Synopsis | |
| Description | Set the scheduling policy and parameters of the specified thread |
| Errors | ENOSYS,EINVAL,ENOTSUP,EPERM,ESRCH |
| Notes | Dependent on support of _XOPEN_REALTIME_THREADS |
Mutex Attributes
All mutex attributes are set in a mutex attribute object by afunction of the form:
| Description and Value(s) | |
| int protocol | Define the scheduling classes for mutex locks PTHREAD_PRIO_NONE,PTHREAD_PRIO_PROTECT, PTHREAD_PRIO_INHERIT |
| int pshared | Defines whether a mutex is shared with other processes. PTHREAD_PROCESS_SHARED, PTHREAD_PROCESS_PRIVATE |
| int prioceiling | Used for mutex attribute priority ceiling values. See POSIX.1 section 13 |
| int type | Application defined mutex locking PTHREAD_MUTEX_NORMAL,PTHREAD_MUTEX_RECURSIVE, |
pthread_mutexattr_init
| Synopsis | |
| Description | Initialize a mutex attribute object |
| Errors | ENOMEM |
pthread_mutexattr_destroy
| Synopsis | |
| Description | Destroy a mutex attribute object |
| Errors | EINVAL |
The mutex attribute manipulation routines supported are as follows:
Mutex Usage
| Description | Initialize a mutex |
| Errors | EAGAIN,ENOMEM,EPERM,EBUSY,EINVAL |
pthread_mutex_destroy
| Synopsis | |
| Description | Destroy a mutex |
| Errors | EBUSY,EINVAL |
pthread_mutex_getprioceiling
| Synopsis | |
| Description | Get the prioceiling value of the specified mutex |
| Errors | ENOSYS, EINVAL,EPERM |
| Notes | This is dependent on _XOPEN_REALTIME_THREADS |
pthread_mutex_setprioceiling
| Synopsis | |
| Description | Set the prioceiling value and return the old prioceiling value in the specified mutex |
| Errors | ENOSYS,EINVAL,EPERM |
| Notes | This is dependent on _XOPEN_REALTIME_THREADS |
pthread_mutex_lock
| Synopsis | |
| Description | Acquire the indicated mutex |
| Errors | EINVAL,EDEADLK |
pthread_mutex_trylock
| Synopsis | |
| Description | Attempt to acquire the indicated mutex |
| Errors | EINVAL,EBUSY |
pthread_mutex_unlock
| Synopsis | |
| Description | Release the previously acquired mutex |
| Errors | EINVAL,EPERM |
Once-only execution
Initialize a once control variable:
| Description | Execute init_routine once |
| Errors | None |
Condition Variable Attributes
All condition variable attributes are set in a condition variableattribute object by a function of the form:
| Description and Value(s) | |
| int pshared | Defines whether a condition variable is shared with other processes. PTHREAD_PROCESS_SHARED,PTHREAD_PROCESS_PRIVATE |
The functions are:
| Description | Initialize a condition variable attribute object |
| Errors | ENOMEM |
pthread_condattr_destroy
| Synopsis | |
| Description | Destroy a condition variable attribute object |
| Errors | EINVAL |
Condition Variable Usage
pthread_cond_init
| Synopsis | |
| Description | Initialize a condition variable |
| Errors | EAGAIN,ENOMEM,EBUSY,EINVAL |
pthread_cond_destroy
| Synopsis | |
| Description | Destroy a condition variable |
| Errors | EBUSY,EINVAL |
pthread_cond_signal
| Synopsis | |
| Description | Unblock at least one thread currently blocked in the specified condition variable |
| Errors | EINVAL |
pthread_cond_broadcast
| Synopsis | |
| Description | Unblock all threads currently blocked on the specified condition variable |
| Errors | EINVAL |
pthread_cond_wait
| Synopsis | |
| Description | Block on the specified condition variable |
| Errors | EINVAL |
| Notes | This function is a cancellation point |
pthread_cond_timedwait
| Synopsis | |
| Description | Block on the specified condition variable not longer than the specified absolute time |
| Errors | ETIMEDOUT,EINVAL |
| Notes | This function is a cancellation point |
Thread Specific Data
pthread_key_create
| Synopsis | |
| Description | Create a thread-specific data key |
| Errors | EAGAIN,ENOMEM |
| Notes | There is a system limit of PTHREAD_KEYS_MAX per process. There is a system limit of PTHREAD_DESTRUCTOR_ITERATIONS calls to destructor per thread exit |
.
pthread_key_delete
| Synopsis | |
| Description | Destroy a thread-specific data key |
| Errors | EINVAL |
pthread_getspecific
| Synopsis | |
| Description | Return the value bound to the given key for the calling thread |
| Errors | ENOMEM,EINVAL |
pthread_setspecific
| Synopsis | |
| Description | Set the value for the given key in the calling thread |
| Errors | ENOMEM,EINVAL |
Signal Management
pthread_sigmask
| Synopsis | |
| Description | Examine or change calling threads signal mask |
| Errors | EINVAL |
| Notes | The value of how can be SIG_BLOCK,SIG_UNBLOCK,SIG_SETMASK |
pthread_kill
| Synopsis | |
| Description | Deliver signal to indicated thread |
| Errors | ESRCH,EINVAL |
sigwait
| Synopsis | |
| Description | Synchronously accept a signal |
| Errors | EINVAL,EINTR |
| Notes | This function is a cancellation point |
Cancellation
pthread_setcancelstate
| Synopsis | |
| Description | Set the cancellation state for the calling thread |
| Errors | EINVAL |
| Notes | Values forstate are PTHREAD_CANCEL_ENABLE,PTHREAD_CANCEL_DISABLE |
pthread_setcanceltype
| Synopsis | |
| Description | Set the cancellation type for the calling thread |
| Errors | EINVAL |
| Notes | Values fortype are PTHREAD_CANCEL_ENABLE,PTHREAD_CANCEL_ASYNCHRONOUS |
pthread_cancel
| Synopsis | |
| Description | Cancel the specified thread |
| Errors | ESRCH |
| Notes | Threads that have been cancelled terminate with a status of PTHREAD_CANCELLED |
pthread_testcancel
| Synopsis | |
| Description | Introduce a cancellation point |
| Errors | None |
| Notes | This function is a cancellation point |
pthread_cleanup_push
| Synopsis | |
| Description | Push an item onto the cancellation stack |
| Errors | None |
pthread_cleanup_pop
| Synopsis | |
| Description | Pop the top item from the cancellation stack and optionally execute it |
| Errors | None |
| Notes | push and pop operations must appear at the same lexical level.executetakes the values 0 or 1. |
Concurrency
pthread_getconcurrency
| Synopsis | |
| Description | Get level of concurrency |
| Errors | None |
pthread_setconcurrency
| Synopsis | |
| Description | Set level of concurrency |
| Errors | EINVAL,EAGAIN |
Read-Write Locks
pthread_rwlock_init
| Synopsis | |
| Description | Initialize a read-write lock object |
| Errors | EAGAIN,ENOMEM,EPERM,EBUSY,EINVAL |
pthread_rwlock_destory
| Synopsis | |
| Description | Destroy a read-write lock object |
| Errors | EBUSY,EINVAL |
pthread_rwlock_rdlock
| Synopsis | |
| Description | Lock a read-write lock object for reading |
| Errors | EINVAL,EDEADLCK,EAGAIN |
pthread_rwlock_tryrdlock
| Synopsis | |
| Description | Lock a read-write lock for reading, unless there is an existing write lock or blocked writers |
| Errors | EBUSY,EINVAL,EDEADLCK,,EAGAIN |
pthread_rwlock_wrlock
| Synopsis | |
| Description | Lock a read-write lock object for writing, block if necessary until the lock becomes available |
| Errors | EINVAL,EDEADLCK |
pthread_rwlock_trywrlock
| Synopsis | |
| Description | Lock a read-write lock for writing, unless there are any existing read or write locks |
| Errors | EBUSY,EINVAL,EDEADLCK |
pthread_rwlock_unlock
| Synopsis | |
| Description | Unlock a read-write lock object |
| Errors | EINVAL,EPERM |
pthread_rwlockattr_init
| Synopsis | |
| Description | Initialize a read-write lock attributes object |
| Errors | ENOMEM |
pthread_rwlockattr_destroy
| Synopsis | |
| Description | Destroy a read-write lock attributes object |
| Errors | EINVAL |
pthread_rwlockattr_getpshared
| Synopsis | |
| Description | Get the value of the process-shared attribute of a read-write lock attributes object |
| Errrors | EINVAL |
pthread_rwlockattr_setpshared
| Synopsis | |
| Description | Set the value of the process-shared attribute of a read-write lock attributes object |
| Errrors | EINVAL |
Atomic Input/Output
pread
| Synopsis | |
| Description | Atomic read of data from file into buffer |
| Errors | See read() |
pwrite
| Synopsis | |
| Description | Atomic write of data from buffer into file |
| Errors | See write() |
Realtime Threads Feature Group
The following threads functions are only supported on UNIX systems if the Realtime Threads Feature group is supported (denoted bythe symbol _XOPEN_REALTIME_THREADS in <unistd.h>).
Thread-safety
The following functions are not guaranteed to be thread-safe onall UNIX systems:
The functions ctermid() and tmpnam() need not be thread-safe ifpassed a NULL argument.
The functions in the Legacy Feature Group need not be thread-safe.
New Threads Related Functions
The following functions offer alternate functionality for implementingthread-safe code, some of these
functions are thread-safe versions of common POSIX.1 functions,some are non thread-safe fast functions to be used with the lockingfacilities also defined in this section.
asctime_r
| Synopsis | |
| Description | Thread safe version of |
ctime_r
| Synopsis | |
| Description | Thread safe version of |
flockfile
| Synopsis | |
| Description |
ftrylockfile
| Synopsis | |
| Description |
funlockfile
| Synopsis | |
| Description |
getc_unlocked
| Synopsis | |
| Description | Fast version of getc() to be used in conjunction with flockfile(), ftrylockfile() and funlockfile() |
getchar_unlocked
| Synopsis | |
| Description | Fast version of getchar() to be used in conjunction with flockfile(), ftrylockfile() and funlockfile() |
getgrgid_r
| Synopsis | |
| Description | Thread safe version of getgrgid() |
getgrnam_r
| Synopsis | |
| Description | Thread safe version of getgrnam() |
getpwnam_r
| Synopsis | |
| Description | Thread safe version of getpwnam() |
getpwuid_r
| Synopsis | |
| Description | Thread safe version of getpwuid() |
gmtime_r
| Synopsis | |
| Description | Thread safe version of gmtime() |
localtime_r
| Synopsis | |
| Description | Thread safe version of localtime() |
putc_unlocked
| Synopsis | |
| Description | Fast version of putc() to be used in conjunction with flockfile(), ftrylockfile() and funlockfile() |
putchar_unlocked
| Synopsis | |
| Description | Fast version of putchar() to be used in conjunction with flockfile(), ftrylockfile() and funlockfile() |
rand_r
| Synopsis | |
| Description | Thread safe version of rand() |
readdir_r
| Synopsis | |
| Description | Thread safe version of readdir() |
strtok_r
| Synopsis | |
| Description | Thread safe version of strtok() |
Read ordownload the complete Single UNIX Specification fromhttp://www.UNIX-systems.org/go/unix.
Copyright © 1997-1998 The Open Group
UNIX is a registered trademark of The Open Group.