HP-UX Reference (11i v1 00/12) - 3 Library Functions N-Z (vol 7)

__________________________________________________________________________________________________________________________________________________________________________________________________
__________________________________________________________________________________________________________________________________________________________________________________________________
STANDARD Printed by: Nora Chuang [nchuang] STANDARD
/build/1111/BRICK/man3/nan.3m
________________________________________________________________
___ ___
p
pthread(3T) pthread(3T)
(Pthread Library)
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 variables
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:
zyx = 21;
Each thread will have a different value associated with zyx.
TLS variables cannot be statically initialized, all are initially zero. Dynamically loaded libraries (via
shl_load()) cannot declare (but may use) TLS variables.
TLS does have a cost in thread creation/termination operations, as TLS space for each thread must be allo-
cated and zeroed, regardless of whether it ever will use the variables. If few threads actually use a large
TLS area, it may be wise to instead use the POSIX TSD (above).
REENTRANT LIBC & STDIO
Because they return pointers to library-internal static data, a number of libc functions cannot be used in
multi-threaded programs. This is because calling these functions in a thread will overwrite the results of
previous calls in other threads. Alternate functions, having the suffix _r (for reentrant), are provided
within libc for threaded programming.
Also, some primitives for synchronization of standard I/O operations are provided.
asctime_r() ,
ctime_r(),
getgrgid_t() ,
getgrnam_r() ,
getlogin_r() ,
getpwnam_r() ,
getpwuid_r() ,
gmtime_t(),
localtime_r(),
rand_r(),
readdir_r() ,
strtok_r(),
ttyname_r()
Provide reentrant versions of previously existing libc functions.
flockfile() ,
ftrylockfile(),
funlock()
Provide explicit synchronization for standard I/O streams.
MISCELLANEOUS FUNCTIONS
The section summarizes some miscellaneous pthread-related functions not covered in the preceding sec-
tions.
HP-UX Release 11i: December 2000 7 Section 3637
___
___