PTHREADS(3) | Library Functions Manual | PTHREADS(3) |
pthreads
— POSIX
1003.1c thread interface
A thread is a flow of control within a process. Each thread represents a minimal amount of state: normally just the CPU state and a signal mask. All other process state (such as memory, file descriptors) is shared among all of the threads in the process.
In OpenBSD, threads use a 1-to-1 implementation, where every thread is independently scheduled by the kernel.
For the purpose of this document, the functions available are grouped in the following categories. For further information, see the individual man page for each function.
The functions available are as follows:
pthread_attr_init
()pthread_attr_destroy
()pthread_attr_getdetachstate
()pthread_attr_setdetachstate
()pthread_attr_getstack
()pthread_attr_setstack
()pthread_attr_getstackaddr
()pthread_attr_setstackaddr
()pthread_attr_getstacksize
()pthread_attr_setstacksize
()pthread_attr_getguardsize
()pthread_attr_setguardsize
()The functions available are as follows:
pthread_barrier_init
()pthread_barrier_destroy
()pthread_barrier_wait
()pthread_barrierattr_init
()pthread_barrierattr_destroy
()The functions available are as follows:
pthread_atfork
()pthread_cleanup_pop
()pthread_cleanup_push
()The functions available are as follows:
pthread_cond_init
()pthread_cond_destroy
()pthread_cond_broadcast
()pthread_cond_signal
()pthread_cond_timedwait
()pthread_cond_wait
()pthread_condattr_init
()pthread_condattr_destroy
()pthread_condattr_getclock
()pthread_condattr_setclock
()The functions available are as follows:
pthread_mutex_init
()pthread_mutex_destroy
()pthread_mutex_lock
()pthread_mutex_timedlock
()pthread_mutex_trylock
()pthread_mutex_unlock
()pthread_mutexattr_init
()pthread_mutexattr_destroy
()pthread_mutexattr_getprioceiling
()pthread_mutexattr_setprioceiling
()pthread_mutexattr_getprotocol
()pthread_mutexattr_setprotocol
()pthread_mutexattr_gettype
()pthread_mutexattr_settype
()The functions available are as follows:
pthread_main_np
()pthread_set_name_np
()pthread_get_name_np
()pthread_stackseg_np
()pthread_yield
()The functions available are as follows:
pthread_key_create
()pthread_key_delete
()pthread_getspecific
()pthread_setspecific
()The functions available are as follows:
pthread_rwlock_init
()pthread_rwlock_destroy
()pthread_rwlock_rdlock
()pthread_rwlock_timedrdlock
()pthread_rwlock_tryrdlock
()pthread_rwlock_wrlock
()pthread_rwlock_timedwrlock
()pthread_rwlock_trywrlock
()pthread_rwlock_unlock
()pthread_rwlockattr_init
()pthread_rwlockattr_destroy
()The functions available are as follows:
pthread_spin_init
()pthread_spin_destroy
()pthread_spin_lock
()pthread_spin_trylock
()pthread_spin_unlock
()The functions available are as follows:
pthread_create
()pthread_cancel
()pthread_detach
()pthread_equal
()pthread_exit
()pthread_getconcurrency
()pthread_setconcurrency
()pthread_join
()pthread_kill
()pthread_once
()pthread_self
()pthread_setcancelstate
()pthread_setcanceltype
()pthread_testcancel
()pthread_sigmask
()pthread_getcpuclockid
()Each thread has a different stack, whether it be provided by a
user attribute, or provided automatically by the system. If a thread
overflows its stack, unpredictable results may occur. System-allocated
stacks (including that of the initial thread) are typically allocated in
such a way that a SIGSEGV
signal is delivered to the
process when a stack overflows.
Signals handlers are normally run on the stack of the currently
executing thread. Hence, if you want to handle the
SIGSEGV
signal from stack overflow for a thread, you
should use
sigaltstack(2) in that
thread.
The following functions are not thread-safe:
The
ctermid
()
and
tmpnam
()
functions are not thread-safe when passed a NULL
argument. The
wcrtomb
(),
wcsrtombs
(),
and
wcsnrtombs
()
functions are not thread-safe when passed a NULL
ps argument.
RTHREAD_DEBUG
intro(3), pthread_atfork(3), pthread_attr_init(3), pthread_attr_setdetachstate(3), pthread_attr_setguardsize(3), pthread_attr_setstack(3), pthread_attr_setstackaddr(3), pthread_attr_setstacksize(3), pthread_barrier_init(3), pthread_barrier_wait(3), pthread_barrierattr_getpshared(3), pthread_barrierattr_init(3), pthread_cancel(3), pthread_cleanup_pop(3), pthread_cleanup_push(3), pthread_cond_broadcast(3), pthread_cond_destroy(3), pthread_cond_init(3), pthread_cond_signal(3), pthread_cond_timedwait(3), pthread_cond_wait(3), pthread_condattr_init(3), pthread_create(3), pthread_detach(3), pthread_equal(3), pthread_exit(3), pthread_get_name_np(3), pthread_getcpuclockid(3), pthread_getspecific(3), pthread_join(3), pthread_key_create(3), pthread_key_delete(3), pthread_kill(3), pthread_main_np(3), pthread_mutex_destroy(3), pthread_mutex_init(3), pthread_mutex_lock(3), pthread_mutex_unlock(3), pthread_mutexattr(3), pthread_once(3), pthread_rwlock_destroy(3), pthread_rwlock_init(3), pthread_rwlock_rdlock(3), pthread_rwlock_unlock(3), pthread_rwlock_wrlock(3), pthread_rwlockattr_destroy(3), pthread_rwlockattr_getpshared(3), pthread_rwlockattr_init(3), pthread_rwlockattr_setpshared(3), pthread_schedparam(3), pthread_self(3), pthread_set_name_np(3), pthread_setspecific(3), pthread_sigmask(3), pthread_spin_init(3), pthread_spin_lock(3), pthread_spin_unlock(3), pthread_stackseg_np(3), pthread_testcancel(3), pthread_yield(3)
The thread library provides functions that conform to ISO/IEC 9945-1:1996 (“POSIX.1”) and various later versions of (“POSIX”). Please consult the manpages for the individual functions for details.
This 1-to-1 implementation of the pthreads
API initially appeared in OpenBSD 3.9 under the name
“librthread” as an alternative to the pure-userspace (N-to-1)
implementation. In OpenBSD 5.2 it became the default
implementation and was renamed to “libpthread”.
Ted Unangst <tedu@openbsd.org>, Kurt Miller <kurt@openbsd.org>, Marco S Hyman <marc@openbsd.org>, Otto Moerbeek <otto@openbsd.org>, and Philip Guenther <guenther@openbsd.org>.
February 4, 2019 | OpenBSD-6.7 |