HP-UX Reference (11i v2 03/08) - 3 Library Functions N-Z (vol 7)
p
pthread(3T) pthread(3T)
(Pthread Library)
Lock/unlock a read-write lock.
pthread_rwlockattr_init()
,
pthread_rwlockattr_destroy()
,
pthread_rwlockattr_getpshared()
,
pthread_rwlockattr_setpshared()
Manage read-write lock attributes used for pthread_rwlock_init()
.
POSIX 1.b SEMAPHORES
The semaphore functions specified in the POSIX 1.b standard can also be used for synchronization in a
multithreaded application.
sem_init(),
sem_destroy()
Initialize/destroy contents of a semaphore.
sem_post(),
sem_wait(),
sem_trywait()
Increment/decrement semaphore value (possibly blocking).
SIGNALS
In a multithreaded process, all threads share signal actions. That is, a signal handler established by one
thread is used in all threads. However, each thread has a separate signal mask, by which it can selec-
tively block signals.
Signals can be sent to other threads within the same process, or to other processes. When a signal is sent
to the process, exactly one thread which does not have that signal blocked will handle the signal. When
sent to a thread within the same process, that thread will handle the signal, perhaps later if the signal is
blocked. Signals whose action is to terminate, stop, or continue will terminate, stop, or continue the
entire process, respectively, even if directed at a particular thread.
pthread_kill() Sends a signal to the given thread.
pthread_sigmask()
Blocks selected signals for the thread.
sigwait(),
sigwaitinfo(),
sigtimedwait()
These functions synchronously wait for given signals.
THREAD-SPECIFIC DATA
Thread-specific data (TSD) is global data that is private or specific to a thread. Each thread has a
different value for the same thread-specific data variable. The global errno is a perfect example of
thread-specific global data.
Each thread-specific data item is associated with a key. The key is shared by all threads. However,
when a thread references the key, it references its own private copy of the data.
pthread_key_create(),
pthread_key_destroy()
These functions manage the thread-specific data keys.
pthread_getspecific(),
pthread_setspecific()
These functions retrieve and assign the data value associated with a key.
The HP-UX compiler supports a thread local storage (TLS) storage class. (This is not a POSIX standard
feature.) TLS is identical to TSD, except functions are not required to create/set/get values. TLS vari-
ables are accessed just like normal global variables. TLS variables can be declared using the following
syntax:
__thread int zyx;
The keyword __thread tells the compiler that zyx is a TLS variable. Now each thread can set or get
TLS with statements such as:
Section 3−−728 Hewlett-Packard Company − 5 − HP-UX 11i Version 2: August 2003