MyWebUniversity.com Home Page
 



Darwin Mac OS X man pages main menu
PTHREAD(3)               BSD Library Functions Manual               PTHREAD(3)

NAME
     pthread -- POSIX thread functions

SYNOPSIS
     ##include <>

DESCRIPTION
     POSIX threads are a set of functions that support applications with
     requirements for multiple flows of control, called threads, within a
     process.  Multithreading is used to improve the performance of a program.

     The POSIX thread functions are summarized in this section in the follow-
     ing groups:

           ]o   Thread Routines

           ]o   Attribute Object Routines

           ]o   Mutex Routines

           ]o   Condition Variable Routines

           ]o   Read/Write Lock Routines

           ]o   Per-Thread Context Routines

           ]o   Cleanup Routines

THREAD ROUTINES
     int pthreadcreate(pthreadt *thread, const pthreadattrt *attr, void
                        *(*startroutine)(void *), void *arg)
                        Creates a new thread of execution.

     int pthreaddetach(pthreadt thread)
                        Marks a thread for deletion.

     int pthreadequal(pthreadt t1, pthreadt t2)
                        Compares two thread IDs.

     void pthreadexit(void *valueptr)
                        Terminates the calling thread.

     int pthreadjoin(pthreadt thread, void **valueptr)
                        Causes the calling thread to wait for the termination
                        of the specified thread.

     int pthreadcancel(pthreadt thread)
                        Cancels execution of a thread.

     int pthreadonce(pthreadoncet *oncecontrol, void
                        (*initroutine)(void))
                        Calls an initialization routine once.

     pthreadt pthreadself(void)
                        Returns the thread ID of the calling thread.

     int pthreadatfork(void (*prepare)(void), void (*parent)(void), void
                        (*child)(void))
                        Registers handlers to be called before and after
                        fork()

ATRIBUTE OBJECT ROUTINES
     int pthreadattrdestroy(pthreadattrt *attr)
                        Destroy a thread attributes object.

     int pthreadattrgetinheritsched(const pthreadattrt *attr, int
                        *inheritsched)
                        Get the inherit scheduling attribute from a thread
                        attributes object.

     int pthreadattrgetschedparam(const pthreadattrt *attr, struct
                        schedparam *param)
                        Get the scheduling parameter attribute from a thread
                        attributes object.

     int pthreadattrgetschedpolicy(const pthreadattrt *attr, int *policy)
                        Get the scheduling policy attribute from a thread
                        attributes object.

     int pthreadattrgetscope(const pthreadattrt *attr, int
                        *contentionscope)
                        Get the contention scope attribute from a thread
                        attributes object.

     int pthreadattrgetstacksize(const pthreadattrt *attr, sizet
                        *stacksize)
                        Get the stack size attribute from a thread attributes
                        object.

     int pthreadattrgetstackaddr(const pthreadattrt *attr, void
                        **stackaddr)
                        Get the stack address attribute from a thread
                        attributes object.

     int pthreadattrgetdetachstate(const pthreadattrt *attr, int
                        *detachstate)
                        Get the detach state attribute from a thread
                        attributes object.

     int pthreadattrinit(pthreadattrt *attr)
                        Initialize a thread attributes object with default
                        values.

     int pthreadattrsetinheritsched(pthreadattrt *attr, int inheritsched)
                        Set the inherit scheduling attribute in a thread
                        attributes object.

     int pthreadattrsetschedparam(pthreadattrt *attr, const struct
                        schedparam *param)
                        Set the scheduling parameter attribute in a thread
                        attributes object.

     int pthreadattrsetschedpolicy(pthreadattrt *attr, int policy)
                        Set the scheduling policy attribute in a thread
                        attributes object.

     int pthreadattrsetscope(pthreadattrt *attr, int contentionscope)
                        Set the contention scope attribute in a thread
                        attributes object.

     int pthreadattrsetstacksize(pthreadattrt *attr, sizet stacksize)
                        Set the stack size attribute in a thread attributes
                        object.

     int pthreadattrsetstackaddr(pthreadattrt *attr, void *stackaddr)
                        Set the stack address attribute in a thread attributes
                        object.

     int pthreadattrsetdetachstate(pthreadattrt *attr, int detachstate)
                        Set the detach state in a thread attributes object.

MUTEX ROUTINES
     int pthreadmutexattrdestroy(pthreadmutexattrt *attr)
                        Destroy a mutex attributes object.

     int pthreadmutexattrinit(pthreadmutexattrt *attr)
                        Initialize a mutex attributes object with default val-
                        ues.

     int pthreadmutexdestroy(pthreadmutext *mutex)
                        Destroy a mutex.

     int pthreadmutexinit(pthreadmutext *mutex, const pthreadmutexattrt
                        *attr)
                        Initialize a mutex with specified attributes.

     int pthreadmutexlock(pthreadmutext *mutex)
                        Lock a mutex and block until it becomes available.

     int pthreadmutextrylock(pthreadmutext *mutex)
                        Try to lock a mutex, but don't block if the mutex is
                        locked by another thread, including the current
                        thread.

     int pthreadmutexunlock(pthreadmutext *mutex)
                        Unlock a mutex.

CONDITION VARIABLE ROUTINES
     int pthreadcondattrinit(pthreadcondattrt *attr)
                        Initialize a condition variable attributes object with
                        default values.

     int pthreadcondattrdestroy(pthreadcondattrt *attr)
                        Destroy a condition variable attributes object.

     int pthreadcondbroadcast(pthreadcondt *cond)
                        Unblock all threads currently blocked on the specified
                        condition variable.

     int pthreadconddestroy(pthreadcondt *cond)
                        Destroy a condition variable.

     int pthreadcondinit(pthreadcondt *cond, const pthreadcondattrt
                        *attr)
                        Initialize a condition variable with specified
                        attributes.

     int pthreadcondsignal(pthreadcondt *cond)
                        Unblock at least one of the threads blocked on the
                        specified condition variable.

     int pthreadcondtimedwait(pthreadcondt *cond, pthreadmutext *mutex,
                        const struct timespec *abstime)
                        Wait no longer than the specified time for a condition
                        and lock the specified mutex.

     int pthreadcondwait(pthreadcondt *, pthreadmutext *mutex)
                        Wait for a condition and lock the specified mutex.

READ/WRITE LOCK ROUTINES
     int pthreadrwlockdestroy(pthreadrwlockt *lock)
                        Destroy a read/write lock object.

     int pthreadrwlockinit(pthreadrwlockt *lock, const
                        pthreadrwlockattrt *attr)
                        Initialize a read/write lock object.

     int pthreadrwlockrdlock(pthreadrwlockt *lock)
                        Lock a read/write lock for reading, blocking until the
                        lock can be acquired.

     int pthreadrwlocktryrdlock(pthreadrwlockt *lock)
                        Attempt to lock a read/write lock for reading, without
                        blocking if the lock is unavailable.

     int pthreadrwlocktrywrlock(pthreadrwlockt *lock)
                        Attempt to lock a read/write lock for writing, without
                        blocking if the lock is unavailable.

     int pthreadrwlockunlock(pthreadrwlockt *lock)
                        Unlock a read/write lock.

     int pthreadrwlockwrlock(pthreadrwlockt *lock)
                        Lock a read/write lock for writing, blocking until the
                        lock can be acquired.

     int pthreadrwlockattrdestroy(pthreadrwlockattrt *attr)
                        Destroy a read/write lock attribute object.

     int pthreadrwlockattrgetpshared(const pthreadrwlockattrt *attr, int
                        *pshared)
                        Retrieve the process shared setting for the read/write
                        lock attribute object.

     int pthreadrwlockattrinit(pthreadrwlockattrt *attr)
                        Initialize a read/write lock attribute object.

     int pthreadrwlockattrsetpshared(pthreadrwlockattrt *attr, int
                        pshared)
                        Set the process shared setting for the read/write lock
                        attribute object.

PER-THREAD CONTEXT ROUTINES
     int pthreadkeycreate(pthreadkeyt *key, void (*routine)(void *))
                        Create a thread-specific data key.

     int pthreadkeydelete(pthreadkeyt key)
                        Delete a thread-specific data key.

     void * pthreadgetspecific(pthreadkeyt key)
                        Get the thread-specific value for the specified key.

     int pthreadsetspecific(pthreadkeyt key, const void *valueptr)
                        Set the thread-specific value for the specified key.

CLEANUP ROUTINES
     void pthreadcleanuppop(int execute)
                        Remove the routine at the top of the calling thread's
                        cancellation cleanup stack and optionally invoke it.

     void pthreadcleanuppush(void (*routine)(void *), void *routinearg)
                        Push the specified cancellation cleanup handler onto
                        the calling thread's cancellation stack.

INSTALATION
     The default system libraries include pthread funcitons. No additional
     libraries or CFLAGS are necessary to use this API.

SEE ALSO
     pthreadcleanuppop(3), pthreadcleanuppush(3),
     pthreadcondbroadcast(3), pthreadconddestroy(3), pthreadcondinit(3),
     pthreadcondsignal(3), pthreadcondtimedwait(3), pthreadcondwait(3),
     pthreadcreate(3), pthreaddetach(3), pthreadequal(3), pthreadexit(3),
     pthreadgetspecific(3), pthreadjoin(3), pthreadkeydelete(3),
     pthreadmutexdestroy(3), pthreadmutexinit(3), pthreadmutexlock(3),
     pthreadmutextrylock(3), pthreadmutexunlock(3), pthreadonce(3),
     pthreadrwlockattrdestroy(3), pthreadrwlockattrgetpshared(3),
     pthreadrwlockattrinit(3), pthreadrwlockattrsetpshared(3),
     pthreadrwlockdestroy(3), pthreadrwlockinit(3),
     pthreadrwlockrdlock(3), pthreadrwlockunlock(3),
     pthreadrwlockwrlock(3), pthreadself(3), pthreadsetspecific(3)

STANDARDS
     The functions in libc with the pthread prefix and not np suffix or
     pthreadrwlock prefix conform to ISO/IEC 9945-1:1996 (``POSIX.1'').

     The functions in libc with the pthread prefix and np suffix are non-
     portable extensions to POSIX threads.

     The functions in libc with the pthreadrwlock prefix are extensions cre-
     ated by The Open Group as part of the Version 2 of the Single UNIX
     Specification (``SUSv2'').

Darwin                         November 5, 2001                         Darwin
Darwin Mac OS X man pages main menu

Contact us      |       About us      |       Term of use      |       Copyright © 2000-2010 MyWebUniversity.com ™