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_mutexattr_getspin_np(3T) pthread_mutexattr_getspin_np(3T)
(Pthread Library)
When the number of threads exceeds the number of processors in a system, a busy-wait on a mutex can
sometimes have an adverse effect. The busy-wait itself can prevent the thread holding the lock from com-
pleting the associated critical section of code. By yielding the processor on occasion, the thread attempting
the lock may allow the thread holding the lock to reach the point at which it can release the lock. How-
ever, it still avoids the costly path to block on the mutex.
The legal values for the yield attribute are:
positive integer
The busy-wait loop in pthread_mutex_lock() will yield the processor after each specified
number of iterations of the spin loop (where the total number of iterations is controlled by the
per-mutex spin attribute). PTHREAD_MUTEX_YIELDNEVER_NP Inhibits yielding in the
mutex lock altogether.
PTHREAD_MUTEX_YIELDFREQDEFAULT_NP
Uses a built-in default value for the frequency of yields in the busy-wait loop.
WARNINGS
The setting of the spin and yield attributes can, as well as improve application performance, easily lead to
degraded performance. The CPU consumption of the application may be increased. Settings which work
well for a small number of threads may do poorly for larger numbers of threads. The optimal settings will
vary depending upon hardware and operating system configuration. Minor changes in the application itself
may require retuning of these attributes.
The programmer must analyze performance carefully, to obtain an understanding of mutex contention
within the application. Then, experiment with different attribute values, evaluating how mutex contention
is affected, response time, and CPU consumption.
RETURN VALUE
Upon successful completion, pthread_mutexattr_setspin_np()
,
pthread_mutexattr_getspin_np()
, pthread_mutex_setyieldfreq_np()
, and
pthread_mutex_getyieldfreq_np()
return zero. Otherwise, an error number is returned to indi-
cate the error (the
errno variable is not set).
ERRORS
For each of the following conditions, if the condition is detected, the
pthread_mutexattr_setspin_np()
, pthread_mutexattr_getspin_np()
,
pthread_mutex_setyieldfreq_np()
, and pthread_mutex_getyieldfreq_np()
functions
return the corresponding error number:
[EINVAL] The value specified by attr, spin,oryield is invalid.
AUTHOR
pthread_mutexattr_getspin_np(), pthread_mutexattr_setspin_np(),
pthread_mutex_getyieldfreq_np(), and pthread_mutex_setyieldfreq_np() were
developed by HP.
SEE ALSO
pthread_create(3T), pthread_mutexattr_init(3T), pthread_mutex_init(3T), rtsched(2).
STANDARDS CONFORMANCE
pthread_mutexattr_setspin_np()
: None.
pthread_mutexattr_getspin_np()
: None.
pthread_mutex_setyieldfreq_np(): None.
pthread_mutex_getyieldfreq_np(): None.
Section 3−−700 − 2 − HP-UX Release 11i: December 2000
___
___