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

p
pthread(3T) pthread(3T)
(Pthread Library)
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.
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
When the application is executed, it produces a per-thread file of pthread events. This is used as input to
the ttv thread trace visualizer facility available in the HP/PAK performance application kit.
There are environment variables defined to control trace data files:
Section 3672 Hewlett-Packard Company 6 HP-UX 11i Version 1: September 2005