Pthread APIs
Before you get started with Pthreads
Many details in Multithreaded
applications will affect your interpretation of how the Pthread APIs work.
Multithreaded applications also contains important general
information about threads. The information includes how process architecture
and process behavior change when running a threaded program, what parts of the
system are not available for use when running a threaded program, and tips on
performance and debugging of threaded jobs.
Programming with Pthreads
Pthread APIs
For information about the examples included with the APIs, see the
Information on the Pthread API examples. See
Code disclaimer information
for information pertaining to code examples.
For information about specific groups of Pthread APIs, see:
The Pthread APIs are:
- pthread_atfork() (Register Fork Handlers)
- pthread_atfork_np() (Register Fork Handlers with Extended Options)
- pthread_attr_destroy() (Destroy Thread Attributes Object) destroys a thread attributes object and allows the system to reclaim any resources associated with that thread attributes object.
- pthread_attr_getdetachstate() (Get Thread Attributes Object Detachstate) returns the detach state attribute from the thread attributes object specified.
- pthread_attr_getguardsize() (Get Guard Size)
- pthread_attr_getinheritsched() (Get Thread Attribute Object Inherit Scheduling Attributes) returns the inheritsched attribute from the thread attributes object specified.
- pthread_attr_getschedparam() (Get Thread Attributes Object Scheduling Parameters) returns the scheduling parameters attribute from the thread attributes object.
- pthread_attr_getschedpolicy() (Get Scheduling Policy)
- pthread_attr_getscope() (Get Scheduling Scope)
- pthread_attr_getstackaddr() (Get Stack Address)
- pthread_attr_getstacksize() (Get Stack Size)
- pthread_attr_init() (Initialize Thread Attributes Object) initializes a thread attributes object to the default thread attributes.
- pthread_attr_setdetachstate() (Set Thread Attributes Object Detachstate) sets the detach state of the thread attributes object.
- pthread_attr_setguardsize() (Set Guard Size)
- pthread_attr_setinheritsched() (Set Thread Attribute Inherit Scheduling Attributes) sets the inheritsched attribute in the thread attributes object specified.
- pthread_attr_setschedparam() (Set Thread Attributes Object Scheduling Parameters) sets the scheduling parameters in the thread attributes object.
- pthread_attr_setschedpolicy() (Set Scheduling Policy)
- pthread_attr_setscope() (Set Scheduling Scope)
- pthread_attr_setstackaddr() (Set Stack Address)
- pthread_attr_setstacksize() (Set Stack Size)
- pthread_cancel() (Cancel Thread) requests cancellation of the target thread.
- pthread_cleanup_peek_np() (Copy Cleanup Handler from Cancellation Cleanup Stack) returns a copy of the cleanup handler entry that the next call to pthread_cleanup_pop() would pop.
- pthread_cleanup_pop() (Pop Cleanup Handler off of Cancellation Cleanup Stack) pops the last cleanup handler from the cancellation cleanup stack.
- pthread_cleanup_push() (Push Cleanup Handler onto Cancellation Cleanup Stack) pushes a cancellation cleanup routine onto the calling threads cancellation cleanup stack.
- pthread_clear_exit_np() (Clear Exit Status of Thread) clears the exit status of the thread.
- pthread_condattr_destroy() (Destroy Condition Variable Attributes Object) destroys the condition variable attributes object specified by attr, and indicates that any storage that the system has associated with the object be de-allocated.
- pthread_condattr_getpshared() (Get Process Shared Attribute from Condition Attributes Object) retrieves the current setting of the process shared attribute from the condition attributes object.
- pthread_condattr_init() (Initialize Condition Variable Attributes Object) initializes the condition variable attributes object specified by attr to the default attributes.
- pthread_condattr_setpshared() (Set Process Shared Attribute in Condition Attributes Object) sets the current pshared attribute for the condition attributes object.
- pthread_cond_broadcast() (Broadcast Condition to All Waiting Threads) wakes up all threads that are currently waiting on the condition variable specified by cond.
- pthread_cond_destroy() (Destroy Condition Variable) destroys the condition variable specified by cond.
- pthread_cond_init() (Initialize Condition Variable) initializes a condition variable object with the specified attributes for use.
- pthread_cond_signal() (Signal Condition to One Waiting Thread) wakes up at least one thread that is currently waiting on the condition variable specified by cond.
- pthread_cond_timedwait() (Timed Wait for Condition) blocks the calling thread, waiting for the condition specified by cond to be signaled or broadcast to.
- pthread_cond_wait() (Wait for Condition) blocks the calling thread, waiting for the condition specified by cond to be signaled or broadcast to.
- pthread_create() (Create Thread) creates a thread with the specified attributes and runs the C function start_routine in the thread with the single pointer argument specified.
- pthread_delay_np() (Delay Thread for Requested Interval) causes the calling thread to delay for the deltatime specified.
- pthread_detach() (Detach Thread) indicates that system resources for the specified thread should be reclaimed when the thread ends.
- pthread_equal() (Compare Two Threads) compares two Pthread handles for equality.
- pthread_exit() (Terminate Calling Thread) terminates the calling thread, making its exit status available to any waiting threads.
- pthread_extendedjoin_np() (Wait for Thread with Extended Options) waits for a thread to terminate, optionally detaches the thread, then returns the threads exit status.
- pthread_getcancelstate_np() (Get Cancel State) gets the current cancel state of the thread.
- pthread_getconcurrency() (Get Process Concurrency Level) retrieves the current concurrency level for the process.
- pthread_getpthreadoption_np() (Get Pthread Run-Time Option Data) gets option data from the pthread run-time for the process.
- pthread_getschedparam() (Get Thread Scheduling Parameters) retrieves the scheduling parameters of the thread.
- pthread_getspecific() (Get Thread Local Storage Value by Key) retrieves the thread local storage value associated with the key. pthread_getspecific() may be called from a data destructor.
- pthread_getthreadid_np() (Retrieve Unique ID for Calling Thread) retrieves the unique integral identifier that can be used to identify the calling thread in some context for application debugging or tracing support.
- pthread_getunique_np() (Retrieve a Unique ID for Target Thread) retrieves the unique integral identifier that can be used to identify the thread in some context for application debugging or tracing support.
- pthread_get_expiration_np() (Get Condition Expiration Time from Relative Time) computes an absolute time by adding the specified relative time (delta) to the current system time.
- pthread_is_initialthread_np() (Check if Running in the Initial Thread) returns true or false, indicating if the current thread is the initial thread of the process.
- pthread_is_multithreaded_np() (Check the Current Number of Threads) returns true or false, indicating whether the current process has more than one thread.
- pthread_join() (Wait for and Detach Thread) waits for a thread to terminate, detaches the thread, then returns the threads exit status.
- pthread_join_np() (Wait for Thread to End) waits for a thread to terminate, then returns the threads exit status, while leaving the data structures of the thread available for a later call to pthread_join(), pthread_join_np(), pthread_detach(), or pthread_extendedjoin_np()
- pthread_key_create() (Create Thread Local Storage Key) creates a thread local storage key for the process and associates the destructor function with that key.
- pthread_key_delete() (Delete Thread Local Storage Key) deletes a process-wide thread local storage key.
- pthread_kill() (Send Signal to Thread) requests that the signal sig be delivered to the specified thread.
- pthread_lock_global_np() (Lock Global Mutex) locks a global mutex provided by the pthreads run-time.
- pthread_mutexattr_destroy() (Destroy Mutex Attributes Object) destroys a mutex attributes object and allows the system to reclaim any resources associated with that mutex attributes object.
- pthread_mutexattr_getkind_np() (Get Mutex Kind Attribute) retrieves the kind attribute from the mutex attributes object specified by attr.
- pthread_mutexattr_getname_np() (Get Name from Mutex Attributes Object) retrieves the name attribute associated with the mutex attribute specified by attr.
- pthread_mutexattr_getprioceiling() (Get Mutex Priority Ceiling Attribute)
- pthread_mutexattr_getprotocol() (Get Mutex Protocol Attribute)
- pthread_mutexattr_getpshared() (Get Process Shared Attribute from Mutex Attributes Object) retrieves the current setting of the process shared attribute from the mutex attributes object.
- pthread_mutexattr_gettype() (Get Mutex Type Attribute) retrieves the type attribute from the mutex attributes object specified by attr.
- pthread_mutexattr_init() (Initialize Mutex Attributes Object) initializes the mutex attributes object referenced by attr to the default attributes.
- pthread_mutexattr_setkind_np() (Set Mutex Kind Attribute) sets the kind attribute in the mutex attributes object specified by attr.
- pthread_mutexattr_setname_np() (Set Name in Mutex Attributes Object) changes the name attribute associated with the mutex attribute specified by attr.
- pthread_mutexattr_setprioceiling() (Set Mutex Priority Ceiling Attribute)
- pthread_mutexattr_setprotocol() (Set Mutex Protocol Attribute)
- pthread_mutexattr_setpshared() (Set Process Shared Attribute in Mutex Attributes Object) sets the current pshared attribute for the mutex attributes object.
- pthread_mutexattr_settype() (Set Mutex Type Attribute) sets the type attribute in the mutex attributes object specified by attr.
- pthread_mutex_destroy() (Destroy Mutex) destroys the named mutex.
- pthread_mutex_getprioceiling() (Get Mutex Priority Ceiling)
- pthread_mutex_init() (Initialize Mutex) initializes a mutex with the specified attributes for use.
- pthread_mutex_lock() (Lock Mutex) acquires ownership of the mutex specified.
- pthread_mutex_setprioceiling() (Set Mutex Priority Ceiling)
- pthread_mutex_timedlock_np() (Lock Mutex with Time-Out) acquires ownership of the mutex specified.
- pthread_mutex_trylock() (Lock Mutex with No Wait) attempts to acquire ownership of the mutex specified without blocking the calling thread.
- pthread_mutex_unlock() (Unlock Mutex) unlocks the mutex specified.
- pthread_once() (Perform One-Time Initialization) performs one time initialization based on a specific once_control variable.
- pthread_rwlockattr_destroy() (Destroy Read/Write Lock Attribute) destroys a read/write lock attributes object and allows the systems to reclaim any resources associated with that read/write lock attributes object.
- pthread_rwlockattr_getpshared() (Get Pshared Read/Write Lock Attribute) retrieves the current setting of the process shared attribute from the read/write lock attributes object.
- pthread_rwlockattr_init() (Initialize Read/Write Lock Attribute) initializes the read/write lock attributes object referred to by attr to the default attributes.
- pthread_rwlockattr_setpshared() (Set Pshared Read/Write Lock Attribute) sets the current pshared attribute for the read/write attributes object.
- pthread_rwlock_destroy() (Destroy Read/Write Lock) destroys the named read/write lock.
- pthread_rwlock_init() (Initialize Read/Write Lock) initializes a new read/write lock with the specified attributes for use.
- pthread_rwlock_rdlock() (Get Shared Read Lock) attempts to acquire a shared read lock on the read/write lock specified by rwlock.
- pthread_rwlock_timedrdlock_np() (Get Shared Read Lock with Time-Out) attempts to acquire a shared read lock on the read/write lock specified by rwlock.
- pthread_rwlock_timedwrlock_np() (Get Exclusive Write Lock with Time-Out) attempts to acquire an exclusive write lock on the read/write lock specified by rwlock.
- pthread_rwlock_tryrdlock() (Get Shared Read Lock with No Wait) attempts to acquire a shared read lock on the read/write lock specified by rwlock.
- pthread_rwlock_trywrlock() (Get Exclusive Write Lock with No Wait) attempts to acquire an exclusive write lock on the read/write lock specified by rwlock.
- pthread_rwlock_unlock() (Unlock Exclusive Write or Shared Read Lock) unlocks a shared read or exclusive write lock held by the calling thread.
- pthread_rwlock_wrlock() (Get Exclusive Write Lock) attempts to acquire an exclusive write lock on the read/write lock specified by rwlock.
- pthread_self() (Get Pthread Handle) returns the Pthread handle of the calling thread.
- pthread_setcancelstate() (Set Cancel State) sets the cancel state to one of PTHREAD_CANCEL_ENABLE or PTHREAD_CANCEL_DISABLE and returns the old cancel state into the location specified by oldstate (if oldstate is non-NULL).
- pthread_setcanceltype() (Set Cancel Type) sets the cancel type to one of PTHREAD_CANCEL_DEFERRED or PTHREAD_CANCEL_ASYNCHRONOUS and returns the old cancel type into the location specified by oldtype (if oldtype is non-NULL)
- pthread_setconcurrency() (Set Process Concurrency Level) sets the current concurrency level for the process.
- pthread_setpthreadoption_np() (Set Pthread Run-Time Option Data) sets option data in the pthread run-time for the process.
- pthread_setschedparam() (Set Target Thread Scheduling Parameters) sets the scheduling parameters of the target thread.
- pthread_setspecific() (Set Thread Local Storage by Key) sets the thread local storage value associated with a key.
- pthread_set_mutexattr_default_np() (Set Default Mutex Attributes Object Kind Attribute) sets the kind attribute in the default mutex attribute object.
- pthread_sigmask() (Set or Get Signal Mask) examines or modifies the signal blocking mask for the current thread.
- pthread_signal_to_cancel_np() (Convert Signals to Cancel Requests) causes a pthread_cancel() to be delivered to the target thread when the first signal specified in set arrives.
- pthread_testcancel() (Create Cancellation Point) creates a cancellation point in the calling thread.
- pthread_test_exit_np() (Test Thread Exit Status) returns the current state of the thread along with its exit status.
- pthread_trace_init_np() (Initialize or Reinitialize Pthread Tracing) initializes or refreshes both the Pthreads library trace level and the application trace level.
- PTHREAD_TRACE_NP() (Execute Code Based on Trace Level (Macro)) is used to execute optional code based on the current application trace level.
- pthread_unlock_global_np() (Unlock Global Mutex) unlocks a global mutex provided by the pthreads run-time.
- sched_yield() (Yield Processor to Another Thread) yields the processor from the currently executing thread to another ready-to-run, active thread of equal or higher priority.