#include <pthread.h>

pthread.h

MkLinux
includes: _types.h, sched.h, time.h, sys/_pthread/_pthread_types.h, sys/_pthread/_pthread_attr_t.h, sys/_pthread/_pthread_cond_t.h, sys/_pthread/_pthread_condattr_t.h, sys/_pthread/_pthread_key_t.h, sys/_pthread/_pthread_mutex_t.h, sys/_pthread/_pthread_mutexattr_t.h, sys/_pthread/_pthread_once_t.h, sys/_pthread/_pthread_rwlock_t.h, sys/_pthread/_pthread_rwlockattr_t.h, sys/_pthread/_pthread_t.h, pthread/qos.h, sys/_types/_mach_port_t.h, sys/_types/_sigset_t.h, sys/cdefs.h, Availability.h
100 functions · 32 macros · 1 typedef

macropthread_cleanup_push

#define pthread_cleanup_push(func, val) {
	     struct __darwin_pthread_handler_rec __handler;
	     pthread_t __self = pthread_self();
	     __handler.__routine = func;
	     __handler.__arg = val;
	     __handler.__next = __self->__cleanup_stack;
	     __self->__cleanup_stack = &__handler;

macropthread_cleanup_pop

#define pthread_cleanup_pop(execute) /* Note: 'handler' must be in this same lexical context! */
	     __self->__cleanup_stack = __handler.__next;
	     if (execute) (__handler.__routine)(__handler.__arg);
   }

macroPTHREAD_CREATE_JOINABLE

#define PTHREAD_CREATE_JOINABLE 1

macroPTHREAD_CREATE_DETACHED

#define PTHREAD_CREATE_DETACHED 2

macroPTHREAD_INHERIT_SCHED

#define PTHREAD_INHERIT_SCHED 1

macroPTHREAD_EXPLICIT_SCHED

#define PTHREAD_EXPLICIT_SCHED 2

macroPTHREAD_CANCEL_ENABLE

#define PTHREAD_CANCEL_ENABLE 0x01
Cancel takes place at next cancellation point

macroPTHREAD_CANCEL_DISABLE

#define PTHREAD_CANCEL_DISABLE 0x00
Cancel postponed

macroPTHREAD_CANCEL_DEFERRED

#define PTHREAD_CANCEL_DEFERRED 0x02
Cancel waits until cancellation point

macroPTHREAD_CANCEL_ASYNCHRONOUS

#define PTHREAD_CANCEL_ASYNCHRONOUS 0x00
Cancel occurs immediately

macroPTHREAD_CANCELED

Value returned from pthread_join() when a thread is canceled
#define PTHREAD_CANCELED ((void *) 1)

macroPTHREAD_SCOPE_SYSTEM

We only support PTHREAD_SCOPE_SYSTEM
#define PTHREAD_SCOPE_SYSTEM 1

macroPTHREAD_SCOPE_PROCESS

#define PTHREAD_SCOPE_PROCESS 2

macroPTHREAD_PROCESS_SHARED

#define PTHREAD_PROCESS_SHARED 1

macroPTHREAD_PROCESS_PRIVATE

#define PTHREAD_PROCESS_PRIVATE 2

macroPTHREAD_PRIO_NONE

Mutex protocol attributes
#define PTHREAD_PRIO_NONE 0

macroPTHREAD_PRIO_INHERIT

#define PTHREAD_PRIO_INHERIT 1

macroPTHREAD_PRIO_PROTECT

#define PTHREAD_PRIO_PROTECT 2

macroPTHREAD_MUTEX_NORMAL

Mutex type attributes
#define PTHREAD_MUTEX_NORMAL 0

macroPTHREAD_MUTEX_ERRORCHECK

#define PTHREAD_MUTEX_ERRORCHECK 1

macroPTHREAD_MUTEX_RECURSIVE

#define PTHREAD_MUTEX_RECURSIVE 2

macroPTHREAD_MUTEX_DEFAULT

#define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_NORMAL

macroPTHREAD_MUTEX_POLICY_FAIRSHARE_NP

Mutex policy attributes
#define PTHREAD_MUTEX_POLICY_FAIRSHARE_NP 1

macroPTHREAD_MUTEX_POLICY_FIRSTFIT_NP

#define PTHREAD_MUTEX_POLICY_FIRSTFIT_NP 3

macroPTHREAD_RWLOCK_INITIALIZER

RWLock variables
#define PTHREAD_RWLOCK_INITIALIZER {_PTHREAD_RWLOCK_SIG_init, {0}}

macroPTHREAD_MUTEX_INITIALIZER

Mutex variables
#define PTHREAD_MUTEX_INITIALIZER {_PTHREAD_MUTEX_SIG_init, {0}}

macroPTHREAD_ERRORCHECK_MUTEX_INITIALIZER

<rdar://problem/10854763>
#define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER {_PTHREAD_ERRORCHECK_MUTEX_SIG_init, {0}}

macroPTHREAD_RECURSIVE_MUTEX_INITIALIZER

#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER {_PTHREAD_RECURSIVE_MUTEX_SIG_init, {0}}

macro_PTHREAD_SWIFT_IMPORTER_NULLABILITY_COMPAT

<rdar://problem/25944576>
#define _PTHREAD_SWIFT_IMPORTER_NULLABILITY_COMPAT() defined(SWIFT_CLASS_EXTRA) && (!defined(SWIFT_SDK_OVERLAY_PTHREAD_EPOCH) || (SWIFT_SDK_OVERLAY_PTHREAD_EPOCH < 1))

macroPTHREAD_COND_INITIALIZER

#define PTHREAD_COND_INITIALIZER {_PTHREAD_COND_SIG_init, {0}}

macroPTHREAD_ONCE_INIT

#define PTHREAD_ONCE_INIT {_PTHREAD_ONCE_SIG_init, {0}}

functionpthread_atfork

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_atfork(
	void (* _Nullable)(void),
	void (* _Nullable)(void),
	void (* _Nullable)(void)
)
Prototypes for all PTHREAD interfaces
man page · June 21, 2004
pthread_atfork(3) — register handlers to be called before and after

functionpthread_attr_destroy

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_attr_destroy(pthread_attr_t *)
man page · December 31, 2007
pthread_attr_destroy(3) — thread attribute operations

functionpthread_attr_getdetachstate

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_attr_getdetachstate(const pthread_attr_t *, int *)
man page · December 31, 2007
pthread_attr_getdetachstate(3) — thread attribute operations

functionpthread_attr_getguardsize

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_attr_getguardsize(const pthread_attr_t * __restrict, size_t * __restrict)
man page · January 8, 2010
pthread_attr_getguardsize(3) — thread attribute operations

functionpthread_attr_getinheritsched

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_attr_getinheritsched(const pthread_attr_t * __restrict, int * __restrict)
man page · December 31, 2007
pthread_attr_getinheritsched(3) — thread attribute operations

functionpthread_attr_getschedparam

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_attr_getschedparam(
	const pthread_attr_t * __restrict,
	struct sched_param * __restrict
)
man page · December 31, 2007
pthread_attr_getschedparam(3) — thread attribute operations

functionpthread_attr_getschedpolicy

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_attr_getschedpolicy(const pthread_attr_t * __restrict, int * __restrict)
man page · December 31, 2007
pthread_attr_getschedpolicy(3) — thread attribute operations

functionpthread_attr_getscope

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_attr_getscope(const pthread_attr_t * __restrict, int * __restrict)
man page · December 31, 2007
pthread_attr_getscope(3) — thread attribute operations

functionpthread_attr_getstack

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_attr_getstack(
	const pthread_attr_t * __restrict,
	void * _Nullable * _Nonnull __restrict,
	size_t * __restrict
)
man page · January 8, 2010
pthread_attr_getstack(3) — thread attribute operations

functionpthread_attr_getstackaddr

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_attr_getstackaddr(
	const pthread_attr_t * __restrict,
	void * _Nullable * _Nonnull __restrict
)
man page · December 31, 2007
pthread_attr_getstackaddr(3) — thread attribute operations

functionpthread_attr_getstacksize

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_attr_getstacksize(const pthread_attr_t * __restrict, size_t * __restrict)
man page · December 31, 2007
pthread_attr_getstacksize(3) — thread attribute operations

functionpthread_attr_init

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_attr_init(pthread_attr_t *)
man page · December 31, 2007
pthread_attr_init(3) — thread attribute operations

functionpthread_attr_setdetachstate

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_attr_setdetachstate(pthread_attr_t *, int)
man page · December 31, 2007
pthread_attr_setdetachstate(3) — thread attribute operations

functionpthread_attr_setguardsize

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_attr_setguardsize(pthread_attr_t *, size_t)
man page · January 8, 2010
pthread_attr_setguardsize(3) — thread attribute operations

functionpthread_attr_setinheritsched

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_attr_setinheritsched(pthread_attr_t *, int)
man page · December 31, 2007
pthread_attr_setinheritsched(3) — thread attribute operations

functionpthread_attr_setschedparam

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_attr_setschedparam(
	pthread_attr_t * __restrict,
	const struct sched_param * __restrict
)
man page · December 31, 2007
pthread_attr_setschedparam(3) — thread attribute operations

functionpthread_attr_setschedpolicy

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_attr_setschedpolicy(pthread_attr_t *, int)
man page · December 31, 2007
pthread_attr_setschedpolicy(3) — thread attribute operations

functionpthread_attr_setscope

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_attr_setscope(pthread_attr_t *, int)
man page · December 31, 2007
pthread_attr_setscope(3) — thread attribute operations

functionpthread_attr_setstack

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_attr_setstack(pthread_attr_t *, void *, size_t)
man page · January 8, 2010
pthread_attr_setstack(3) — thread attribute operations

functionpthread_attr_setstackaddr

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_attr_setstackaddr(pthread_attr_t *, void *)
man page · December 31, 2007
pthread_attr_setstackaddr(3) — thread attribute operations

functionpthread_attr_setstacksize

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_attr_setstacksize(pthread_attr_t *, size_t)
man page · December 31, 2007
pthread_attr_setstacksize(3) — thread attribute operations

functionpthread_cancel

__API_AVAILABLE(macos(10.4), ios(2.0)) __DARWIN_ALIAS(pthread_cancel)
int pthread_cancel(pthread_t)
man page · January 17, 1999
pthread_cancel(3) — cancel execution of a thread

functionpthread_cond_broadcast

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_cond_broadcast(pthread_cond_t *)
man page · July 28, 1998
pthread_cond_broadcast(3) — unblock all threads waiting for a condition variable

functionpthread_cond_destroy

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_cond_destroy(pthread_cond_t *)
man page · July 28, 1998
pthread_cond_destroy(3) — destroy a condition variable

functionpthread_cond_init

__API_AVAILABLE(macos(10.4), ios(2.0)) __DARWIN_ALIAS(pthread_cond_init)
int pthread_cond_init(
	pthread_cond_t * __restrict,
	const pthread_condattr_t * _Nullable __restrict
)
man page · November 4, 2006
pthread_cond_init(3) — create a condition variable

functionpthread_cond_signal

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_cond_signal(pthread_cond_t *)
man page · July 28, 1998
pthread_cond_signal(3) — unblock a thread waiting for a condition variable

functionpthread_cond_timedwait

__API_AVAILABLE(macos(10.4), ios(2.0)) __PTHREAD_SWIFT_UNAVAILABLE_FROM_ASYNC("Use an asynchronous wait instead of a synchronous wait") __DARWIN_ALIAS_C(pthread_cond_timedwait)
int pthread_cond_timedwait(
	pthread_cond_t * __restrict,
	pthread_mutex_t * __restrict,
	const struct timespec * _Nullable __restrict
)
man page · May 9, 2010
pthread_cond_timedwait(3) — "wait on a condition variable for a specific amount of time"

functionpthread_cond_wait

__API_AVAILABLE(macos(10.4), ios(2.0)) __PTHREAD_SWIFT_UNAVAILABLE_FROM_ASYNC("Use an asynchronous wait instead of a synchronous wait") __DARWIN_ALIAS_C(pthread_cond_wait)
int pthread_cond_wait(pthread_cond_t * __restrict, pthread_mutex_t * __restrict)
man page · February 16, 2006
pthread_cond_wait(3) — wait on a condition variable

functionpthread_condattr_destroy

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_condattr_destroy(pthread_condattr_t *)
man page · May 9, 2010
pthread_condattr_destroy(3) — condition attribute operations

functionpthread_condattr_init

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_condattr_init(pthread_condattr_t *)
man page · May 9, 2010
pthread_condattr_init(3) — condition attribute operations

functionpthread_condattr_getpshared

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_condattr_getpshared(const pthread_condattr_t * __restrict, int * __restrict)

functionpthread_condattr_setpshared

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_condattr_setpshared(pthread_condattr_t *, int)

functionpthread_create

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_create(
	pthread_t _Nullable * _Nonnull __restrict,
	const pthread_attr_t * _Nullable __restrict,
	void * _Nullable (* _Nonnull)(void * _Nullable),
	void * _Nullable __restrict
)
man page · March 15, 2014
pthread_create(3) — create a new thread

functionpthread_detach

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_detach(pthread_t)
man page · April 4, 1996
pthread_detach(3) — detach a thread

functionpthread_equal

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_equal(pthread_t _Nullable, pthread_t _Nullable)
man page · April 4, 1996
pthread_equal(3) — compare thread IDs

functionpthread_exit

__API_AVAILABLE(macos(10.4), ios(2.0)) __PTHREAD_SWIFT_UNAVAILABLE_FROM_ASYNC("Thread lifecycle is owned by Swift Concurrency runtime") __dead2
void pthread_exit(void * _Nullable)
man page · March 15, 2014
pthread_exit(3) — terminate the calling thread

functionpthread_getconcurrency

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_getconcurrency(void)

functionpthread_getschedparam

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_getschedparam(
	pthread_t,
	int * _Nullable __restrict,
	struct sched_param * _Nullable __restrict
)
man page · October 16, 2006
pthread_getschedparam(3) — thread scheduling parameter manipulation

functionpthread_getspecific

__PTHREAD_SWIFT_UNAVAILABLE_FROM_ASYNC("Use Task Local Values instead") __API_AVAILABLE(macos(10.4), ios(2.0))
void* _Nullable pthread_getspecific(pthread_key_t)
man page · April 4, 1996
pthread_getspecific(3) — get a thread-specific data value

functionpthread_join

__API_AVAILABLE(macos(10.4), ios(2.0)) __PTHREAD_SWIFT_UNAVAILABLE_FROM_ASYNC("Use an asynchronous wait instead of a synchronous wait") __DARWIN_ALIAS_C(pthread_join)
int pthread_join(pthread_t, void * _Nullable * _Nullable)
man page · January 23, 2010
pthread_join(3) — wait for thread termination

functionpthread_key_create

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_key_create(pthread_key_t *, void (* _Nullable)(void *))
man page · April 4, 1996
pthread_key_create(3) — thread-specific data key creation

functionpthread_key_delete

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_key_delete(pthread_key_t)
man page · April 4, 1996
pthread_key_delete(3) — delete a thread-specific data key

functionpthread_mutex_destroy

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_mutex_destroy(pthread_mutex_t *)
man page · July 29, 1998
pthread_mutex_destroy(3) — free resources allocated for a mutex

functionpthread_mutex_getprioceiling

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_mutex_getprioceiling(const pthread_mutex_t * __restrict, int * __restrict)

functionpthread_mutex_init

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_mutex_init(
	pthread_mutex_t * __restrict,
	const pthread_mutexattr_t * _Nullable __restrict
)
man page · November 4, 2006
pthread_mutex_init(3) — create a mutex

functionpthread_mutex_lock

__API_AVAILABLE(macos(10.4), ios(2.0)) __PTHREAD_SWIFT_UNAVAILABLE_FROM_ASYNC("Use OSAllocatedUnfairLock's withLock or NSLock for async-safe scoped locking")
int pthread_mutex_lock(pthread_mutex_t *)
man page · January 31, 2006
pthread_mutex_lock(3) — lock a mutex

functionpthread_mutex_setprioceiling

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_mutex_setprioceiling(pthread_mutex_t * __restrict, int, int * __restrict)

functionpthread_mutex_trylock

__API_AVAILABLE(macos(10.4), ios(2.0)) __PTHREAD_SWIFT_UNAVAILABLE_FROM_ASYNC("Use OSAllocatedUnfairLock's withLockIfAvailable or NSLock for async-safe scoped locking")
int pthread_mutex_trylock(pthread_mutex_t *)
man page · July 30, 1998
pthread_mutex_trylock(3) — attempt to lock a mutex without blocking

functionpthread_mutex_unlock

__API_AVAILABLE(macos(10.4), ios(2.0)) __PTHREAD_SWIFT_UNAVAILABLE_FROM_ASYNC("Use OSAllocatedUnfairLock's withLock or NSLock for async-safe scoped locking")
int pthread_mutex_unlock(pthread_mutex_t *)
man page · July 30, 1998
pthread_mutex_unlock(3) — unlock a mutex

functionpthread_mutexattr_destroy

__API_AVAILABLE(macos(10.4), ios(2.0)) __DARWIN_ALIAS(pthread_mutexattr_destroy)
int pthread_mutexattr_destroy(pthread_mutexattr_t *)
man page · July 9, 2010
pthread_mutexattr_destroy(3) — mutex attribute operations

functionpthread_mutexattr_getprioceiling

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_mutexattr_getprioceiling(
	const pthread_mutexattr_t * __restrict,
	int * __restrict
)
man page · July 9, 2010
pthread_mutexattr_getprioceiling(3) — mutex attribute operations

functionpthread_mutexattr_getprotocol

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_mutexattr_getprotocol(
	const pthread_mutexattr_t * __restrict,
	int * __restrict
)
man page · July 9, 2010
pthread_mutexattr_getprotocol(3) — mutex attribute operations

functionpthread_mutexattr_getpshared

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_mutexattr_getpshared(const pthread_mutexattr_t * __restrict, int * __restrict)

functionpthread_mutexattr_gettype

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_mutexattr_gettype(const pthread_mutexattr_t * __restrict, int * __restrict)
man page · July 9, 2010
pthread_mutexattr_gettype(3) — mutex attribute operations

functionpthread_mutexattr_getpolicy_np

__API_AVAILABLE(macos(10.13.4), ios(11.3), watchos(4.3), tvos(11.3))
int pthread_mutexattr_getpolicy_np(
	const pthread_mutexattr_t * __restrict,
	int * __restrict
)

functionpthread_mutexattr_init

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_mutexattr_init(pthread_mutexattr_t *)
man page · July 9, 2010
pthread_mutexattr_init(3) — mutex attribute operations

functionpthread_mutexattr_setprioceiling

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *, int)
man page · July 9, 2010
pthread_mutexattr_setprioceiling(3) — mutex attribute operations

functionpthread_mutexattr_setprotocol

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_mutexattr_setprotocol(pthread_mutexattr_t *, int)
man page · July 9, 2010
pthread_mutexattr_setprotocol(3) — mutex attribute operations

functionpthread_mutexattr_setpshared

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_mutexattr_setpshared(pthread_mutexattr_t *, int)

functionpthread_mutexattr_settype

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_mutexattr_settype(pthread_mutexattr_t *, int)
man page · July 9, 2010
pthread_mutexattr_settype(3) — mutex attribute operations

functionpthread_mutexattr_setpolicy_np

__API_AVAILABLE(macos(10.7), ios(5.0))
int pthread_mutexattr_setpolicy_np(pthread_mutexattr_t *, int)

functionpthread_once

__SWIFT_UNAVAILABLE_MSG("Use lazily initialized globals instead") __API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_once(pthread_once_t *, void (* _Nonnull)(void))
man page · April 4, 1996
pthread_once(3) — dynamic package initialization

functionpthread_rwlock_destroy

__API_AVAILABLE(macos(10.4), ios(2.0)) __DARWIN_ALIAS(pthread_rwlock_destroy)
int pthread_rwlock_destroy(pthread_rwlock_t *)
man page · August 4, 1998
pthread_rwlock_destroy(3) — destroy a read/write lock

functionpthread_rwlock_init

__API_AVAILABLE(macos(10.4), ios(2.0)) __DARWIN_ALIAS(pthread_rwlock_init)
int pthread_rwlock_init(
	pthread_rwlock_t * __restrict,
	const pthread_rwlockattr_t * _Nullable __restrict
)
man page · August 4, 1998
pthread_rwlock_init(3) — initialize a read/write lock

functionpthread_rwlock_rdlock

__API_AVAILABLE(macos(10.4), ios(2.0)) __PTHREAD_SWIFT_UNAVAILABLE_FROM_ASYNC("Use async-safe scoped locking instead") __DARWIN_ALIAS(pthread_rwlock_rdlock)
int pthread_rwlock_rdlock(pthread_rwlock_t *)
man page · August 4, 1998
pthread_rwlock_rdlock(3) — acquire a read/write lock for reading

functionpthread_rwlock_tryrdlock

__API_AVAILABLE(macos(10.4), ios(2.0)) __PTHREAD_SWIFT_UNAVAILABLE_FROM_ASYNC("Use async-safe scoped locking instead") __DARWIN_ALIAS(pthread_rwlock_tryrdlock)
int pthread_rwlock_tryrdlock(pthread_rwlock_t *)
man page · August 4, 1998
pthread_rwlock_tryrdlock(3) — acquire a read/write lock for reading

functionpthread_rwlock_trywrlock

__API_AVAILABLE(macos(10.4), ios(2.0)) __PTHREAD_SWIFT_UNAVAILABLE_FROM_ASYNC("Use async-safe scoped locking instead") __DARWIN_ALIAS(pthread_rwlock_trywrlock)
int pthread_rwlock_trywrlock(pthread_rwlock_t *)
man page · August 4, 1998
pthread_rwlock_trywrlock(3) — acquire a read/write lock for writing

functionpthread_rwlock_wrlock

__API_AVAILABLE(macos(10.4), ios(2.0)) __PTHREAD_SWIFT_UNAVAILABLE_FROM_ASYNC("Use async-safe scoped locking instead") __DARWIN_ALIAS(pthread_rwlock_wrlock)
int pthread_rwlock_wrlock(pthread_rwlock_t *)
man page · August 4, 1998
pthread_rwlock_wrlock(3) — acquire a read/write lock for writing

functionpthread_rwlock_unlock

__API_AVAILABLE(macos(10.4), ios(2.0)) __PTHREAD_SWIFT_UNAVAILABLE_FROM_ASYNC("Use async-safe scoped locking instead") __DARWIN_ALIAS(pthread_rwlock_unlock)
int pthread_rwlock_unlock(pthread_rwlock_t *)
man page · August 4, 1998
pthread_rwlock_unlock(3) — release a read/write lock

functionpthread_rwlockattr_destroy

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_rwlockattr_destroy(pthread_rwlockattr_t *)
man page · August 4, 1998
pthread_rwlockattr_destroy(3) — destroy a read/write lock

functionpthread_rwlockattr_getpshared

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_rwlockattr_getpshared(
	const pthread_rwlockattr_t * __restrict,
	int * __restrict
)
man page · March 22, 1999
pthread_rwlockattr_getpshared(3) — get the process shared attribute

functionpthread_rwlockattr_init

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_rwlockattr_init(pthread_rwlockattr_t *)
man page · August 4, 1998
pthread_rwlockattr_init(3) — initialize a read/write lock

functionpthread_rwlockattr_setpshared

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *, int)
man page · August 4, 1998
pthread_rwlockattr_setpshared(3) — set the process shared attribute

functionpthread_self

__API_AVAILABLE(macos(10.4), ios(2.0))
pthread_t pthread_self(void)
man page · April 4, 1996
pthread_self(3) — get the calling thread's ID

functionpthread_setcancelstate

__API_AVAILABLE(macos(10.4), ios(2.0)) __PTHREAD_SWIFT_UNAVAILABLE_FROM_ASYNC("Use Task cancellation instead") __DARWIN_ALIAS(pthread_setcancelstate)
int pthread_setcancelstate(int, int * _Nullable)
man page · June 11, 2013
pthread_setcancelstate(3) — set cancelability state

functionpthread_setcanceltype

__API_AVAILABLE(macos(10.4), ios(2.0)) __PTHREAD_SWIFT_UNAVAILABLE_FROM_ASYNC("Use Task cancellation instead") __DARWIN_ALIAS(pthread_setcanceltype)
int pthread_setcanceltype(int, int * _Nullable)
man page · June 11, 2013
pthread_setcanceltype(3) — set cancelability state

functionpthread_setconcurrency

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_setconcurrency(int)

functionpthread_setschedparam

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_setschedparam(pthread_t, int, const struct sched_param *)
man page · October 16, 2006
pthread_setschedparam(3) — thread scheduling parameter manipulation

functionpthread_setspecific

__API_AVAILABLE(macos(10.4), ios(2.0)) __PTHREAD_SWIFT_UNAVAILABLE_FROM_ASYNC("Use Task Local Values instead")
int pthread_setspecific(pthread_key_t, const void * _Nullable)
man page · April 4, 1996
pthread_setspecific(3) — set a thread-specific data value

functionpthread_testcancel

__API_AVAILABLE(macos(10.4), ios(2.0)) __PTHREAD_SWIFT_UNAVAILABLE_FROM_ASYNC("Use Task cancellation instead") __DARWIN_ALIAS(pthread_testcancel)
void pthread_testcancel(void)
man page · June 11, 2013
pthread_testcancel(3) — set cancelability state

functionpthread_is_threaded_np

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_is_threaded_np(void)
returns non-zero if pthread_create or cthread_fork have been called

functionpthread_threadid_np

__API_AVAILABLE(macos(10.6), ios(3.2))
int pthread_threadid_np(pthread_t _Nullable, __uint64_t* _Nullable)
man page · April 12, 2016
pthread_threadid_np(3) — get the calling thread's unique ID

functionpthread_getname_np

__API_AVAILABLE(macos(10.6), ios(3.2))
int pthread_getname_np(pthread_t, char*, size_t)
SPI to set and get pthread name

functionpthread_setname_np

__API_AVAILABLE(macos(10.6), ios(3.2)) __PTHREAD_SWIFT_UNAVAILABLE_FROM_ASYNC("Thread lifecycle is owned by Swift Concurrency runtime")
int pthread_setname_np(const char*)
man page · February 13, 2003
pthread_setname_np(3) — set the thread name

functionpthread_main_np

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_main_np(void)
returns non-zero if the current thread is the main thread
man page · February 13, 2003
pthread_main_np(3) — identify the initial thread

functionpthread_mach_thread_np

__API_AVAILABLE(macos(10.4), ios(2.0))
mach_port_t pthread_mach_thread_np(pthread_t)
return the mach thread bound to the pthread

functionpthread_get_stacksize_np

__API_AVAILABLE(macos(10.4), ios(2.0))
size_t pthread_get_stacksize_np(pthread_t)

functionpthread_get_stackaddr_np

__API_AVAILABLE(macos(10.4), ios(2.0))
void* pthread_get_stackaddr_np(pthread_t)

functionpthread_cond_signal_thread_np

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_cond_signal_thread_np(pthread_cond_t *, pthread_t _Nullable)
Like pthread_cond_signal(), but only wake up the specified pthread

functionpthread_cond_timedwait_relative_np

__API_AVAILABLE(macos(10.4), ios(2.0)) __PTHREAD_SWIFT_UNAVAILABLE_FROM_ASYNC("Use an asynchronous wait instead of a synchronous wait")
int pthread_cond_timedwait_relative_np(
	pthread_cond_t *,
	pthread_mutex_t *,
	const struct timespec * _Nullable
)
Like pthread_cond_timedwait, but use a relative timeout

functionpthread_create_suspended_np

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_create_suspended_np(
	pthread_t _Nullable * _Nonnull,
	const pthread_attr_t * _Nullable,
	void * _Nullable (* _Nonnull)(void * _Nullable),
	void * _Nullable
)
Like pthread_create(), but leaves the thread suspended

functionpthread_kill

__API_AVAILABLE(macos(10.4), ios(2.0))
int pthread_kill(pthread_t, int)
man page · Feb 05, 2002
pthread_kill(2) — send a signal to a specified thread

functionpthread_from_mach_thread_np

__API_AVAILABLE(macos(10.5), ios(2.0))
_Nullable pthread_t pthread_from_mach_thread_np(mach_port_t)

functionpthread_sigmask

__API_AVAILABLE(macos(10.4), ios(2.0)) __DARWIN_ALIAS(pthread_sigmask)
int pthread_sigmask(int, const sigset_t * _Nullable, sigset_t * _Nullable)
man page · February 19, 2011
pthread_sigmask(2) — examine and/or change a thread's signal mask

functionpthread_yield_np

__API_AVAILABLE(macos(10.4), ios(2.0)) __PTHREAD_SWIFT_UNAVAILABLE_FROM_ASYNC("Use Task.yield(), or await a condition instead of spinning")
void pthread_yield_np(void)
man page · September 18, 2006
pthread_yield_np(3) — yield control of the current thread

functionpthread_jit_write_protect_np

__API_AVAILABLE(macos(11.0)) __API_UNAVAILABLE(ios, tvos, watchos, driverkit)
void pthread_jit_write_protect_np(int enabled)
man page · May 1, 2020
pthread_jit_write_protect_np(3) — thread JIT region write protection settings

functionpthread_jit_write_protect_supported_np

__API_AVAILABLE(macos(11.0), ios(17.4)) __API_UNAVAILABLE(tvos, watchos, driverkit, visionos)
int pthread_jit_write_protect_supported_np(void)
man page · May 1, 2020
pthread_jit_write_protect_supported_np(3) — thread JIT region write protection settings

typedefpthread_jit_write_callback_t

@typedef pthread_jit_write_callback_t The type of a function that can be supplied to {@link pthread_jit_write_with_callback_np} to write to the MAP_JIT region while it is writeable. @param ctx A pointer to context that will be passed through to the callback function. @result A result code to be returned to the caller of @{link pthread_jit_write_with_callback_np}. The system does not interpret/act on the value of this result.
typedef int (*pthread_jit_write_callback_t)(void * _Nullable ctx)

macroPTHREAD_JIT_WRITE_ALLOW_CALLBACKS_NP

@define PTHREAD_JIT_WRITE_ALLOW_CALLBACKS_NP A macro to be used at file scope to list the functions allowed to be passed to {@link pthread_jit_write_with_callback_np} to write to the MAP_JIT region while it is writeable. It may be invoked only once per executable/library. @param callbacks The pthread_jit_write_callback_t functions to allow. They should be supplied as a comma-delimited list.
#define PTHREAD_JIT_WRITE_ALLOW_CALLBACKS_NP(...) __attribute__((__used__, __section__("__DATA_CONST,__pth_jit_func")))
		static const pthread_jit_write_callback_t __pthread_jit_write_callback_allowlist[] = {
			__VA_ARGS__, NULL
		}

functionpthread_jit_write_with_callback_np

__API_AVAILABLE(macos(11.4), ios(17.4)) __API_UNAVAILABLE(tvos, watchos, driverkit, visionos) __SWIFT_UNAVAILABLE_MSG("This interface cannot be safely used from Swift")
int pthread_jit_write_with_callback_np(
	pthread_jit_write_callback_t _Nonnull callback,
	void * _Nullable ctx
)
@function pthread_jit_write_with_callback_np @abstract Toggles per-thread write-protection of the MAP_JIT region to writeable, invokes an allowed callback function to write to it, and toggles protection back to executable. @param callback The callback function to invoke to write to the MAP_JIT region. It must be statically allowed using {@link PTHREAD_JIT_WRITE_ALLOW_CALLBACKS_NP}. @param ctx Context to pass through to the invocation of the callback function. @result The result code returned by the callback function. @discussion This function assumes that the MAP_JIT region has executable protection when called. It is therefore invalid to call it recursively from within a write callback. The implementation does not detect such invalid recursive calls, so the client is responsible for preventing them. Callbacks _must not_ perform any non-local transfer of control flow (e.g. throw an exception, longjmp(3)), as doing so would leave the MAP_JIT region writeable. On systems where pthread_jit_write_protect_supported_np(3) is false, this function calls @callback directly and does nothing else. This function only enforces that @callback is allowed if the caller has the com.apple.security.cs.jit-write-allowlist entitlement. That entitlement also disallows use of pthread_jit_write_protect_np(3). Adopting the entitlement is therefore crucial in realizing the security benefits of this interface. If the entitlement is not present then this function toggles protection of the MAP_JIT to writeable, calls @callback and then toggles protection back to executable, without validating that @callback is an allowed function. This behavior is intended to permit independent adoption of this interface by libraries - once all libraries in an application have adopted, the application should add the entitlement. By default, only callbacks in libraries/images present at process start-up are allowed - callbacks in images loaded dynamically via dlopen(3)/etc. are not permitted. However, if the additional entitlement com.apple.security.cs.jit-write-allowlist-freeze-late is _also_ present, any callbacks in dlopen'd libraries are also added to the set of allowed callbacks until the {@link pthread_jit_write_freeze_callbacks_np} function is called. The goal of this interface is to allow applications that execute JIT-compiled code to mitigate against attempts from attackers to escalate to code execution by getting their own instructions written to the MAP_JIT region. Callbacks should assume an attacker can control the input to this function. They must therefore carefully validate the data that they are passed and do so using as little attackable state as possible. This means simplifying control flow and avoiding spills of sensitive registers (e.g. those used for validation or control flow). In the event a callback detects that its input is invalid, it should either abort in the simplest fashion possible (preferring e.g. __builtin_trap() over abort(3), the latter being encumbered by various conformance requirements) or return a result indicating failure.
man page · May 1, 2020
pthread_jit_write_with_callback_np(3) — thread JIT region write protection settings

functionpthread_jit_write_freeze_callbacks_np

__API_AVAILABLE(macos(12.1), ios(17.4)) __API_UNAVAILABLE(tvos, watchos, driverkit, visionos)
void pthread_jit_write_freeze_callbacks_np(void)
@function pthread_jit_write_freeze_callbacks_np @abstract Freezes the set of allowed pthread JIT write callbacks, preventing any callbacks in subsequently dlopen'd libraries from being allowed as arguments to {@link pthread_jit_write_with_callback_np} @discussion If the com.apple.security.cs.jit-write-allowlist-freeze-late entitlement is present, this function must be called exactly once after all libraries containing JIT write callbacks have been loaded to prevent any further runtime modifications to the set of allowed callbacks. Failing to call this function before calling pthread_jit_write_with_callback_np(3) for the first time is an error, as is calling it multiple times. If the jit-write-allowlist-freeze-late entitlement is not present, calling this function is an error. If an application does not need to dlopen(3) any libraries or frameworks containing needed JIT write callbacks, it is best to avoid the jit-write-allowlist-freeze-late entitlement and accompanying need to call this function, as this allows the runtime to automatically freeze the set of allowed callbacks early in process initialization.
man page · May 1, 2020
pthread_jit_write_freeze_callbacks_np(3) — thread JIT region write protection settings

functionpthread_cpu_number_np

__API_AVAILABLE(macos(11.0), ios(14.2), tvos(14.2), watchos(7.1))
int pthread_cpu_number_np(size_t *cpu_number_out)
@function pthread_cpu_number_np @param cpu_number_out The CPU number that the thread was running on at the time of query. This cpu number is in the interval [0, ncpus) (from sysctlbyname("hw.ncpu")) @result This function returns 0 or the value of errno if an error occurred. @note Optimizations of per-CPU datastructures based on the result of this function still require synchronization since it is not guaranteed that the thread will still be on the same CPU by the time the function returns.