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)
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 availablein the HP/PAK performance application kit.
There are environment variables defined to control trace data files:
THR_TRACE_DIR
Where to place the trace data files. If this is not defined, the files go to the current working directory.
THR_TRACE_SYNC
By default, trace records are buffered and only written to the file when the buffer is full. If this vari-
able is set to any non-NULL value, data is immediately written to the trace file.
THR_TRACE_EVENTS
By default, all pthread events are traced. If this variable is defined, only the categories defined will be
traced. Each category is separated by a ’:’. The possible trace categories are:
thread:cond:mutex:rwlock
For example, to only trace thread and mutex operations set the THR_TRACE_EVENTS variable to:
thread:mutex
Details of the trace file record format can be found in /usr/include/sys/trace_thread.h
.
See the ttv(1) manpage and built-in graphical help system for more information on the use of the trace
information.
PERFORMANCE CONSIDERATIONS
Often, an application is designed to be multithreaded to improve performance over its single-threaded coun-
terparts. However, the multithreaded approach requires some attention to issues not always of concern in
the single-threaded case. These are issues traditionally associated with the programming of multiprocessor
systems.
The design must employ a lock granularity appropriate to the data structures and access patterns.
Coarse-grained locks, which protect relatively large amounts of data, can lead to undesired lock contention,
reducing the potential parallelism of the application. On the other hand, employing very fine-grained locks,
which protect very small amounts of data, can consume processor cycles with too much locking activity.
The use of thread-specific data (TSD) or thread-localstorage (TLS) must be traded off, as described above
(see THREAD-SPECIFIC DATA).
Mutex spin and yield frequency attributes can be used to tune mutex behavior to the application. See
pthread_mutexattr_setspin_np(3T) and pthread_mutex_setyieldfreq_np(3T) for more information.
The default stacksize attribute can be set to improve system thread caching behavior. See
pthread_default_stacksize_np(3T) for more information.
Because multiple threads are actually running simultaneously, they can be accessing the same data from
multiple processors. The hardware processors coordinate their caching of data such that no processor is
Section 3638 8 HP-UX Release 11i: December 2000
___
___