pthread.3t (2010 09)
p
pthread(3T) pthread(3T)
(Pthread Library)
zyx = 21;
Each thread will have a different value associated with
zyx.
TLS variables can be statically initialized. Uninitialized TLS variables will be set to zero. Dynamically
loaded libraries (with
shl_load()) can declare and use TLS variables.
TLS does have a cost in thread creation/termination operations, as TLS space for each thread must be
allocated and initialized, regardless of whether it will ever use the variables. This is true for modules
linked statically at startup. In case of dynamically loaded liabraries (with
sh_load()), TLS space for a
thread will be allocated when the TLS variables are accessed by it. If few threads actually use a large
TLS area, it may be wise to use the POSIX TSD instead (above).
REENTRANT LIBC & STDIO
Because they return pointers to library-internal static data, a number of libc functions cannot be used in
multithreaded 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.
pthread_atfork() Establish special functions to be called just prior to and just subsequent to a
fork() operation.
pthread_equal() Tests whether two pthread_t values represent the same pthread.
pthread_once() Executes given function just once in a process, regardless of how many threads
make the same call. (Useful for one-time data initialization.)
pthread_self() Returns identifier (pthread_t) of calling thread.
THREAD DEBUGGING
Debugging of multithreaded programs is supported in the standard HP-UX debugger,
dde. When any
thread is to be stopped due to a debugger event, the debugger will stop all threads. The register state,
stack, and data for any thread can be interrogated and manipulated.
See the dde(1) manpage and built-in graphical help system for more information.
TRACING FACILITIES
HP-UX provides a tracing facility for pthread operations. To use it, you must link your application using
the tracing version of the library:
cc -D_POSIX_C_SOURCE=199506L -o myapp myapp.c -lpthread_tr -lcl
6 Hewlett-Packard Company − 6 − HP-UX 11i Version 3: September 2010