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

p
pthread_mutexattr_getspin_np(3T) pthread_mutexattr_getspin_np(3T)
(Pthread Library)
The legal values for the spin attribute are:
positive integer
The pthread_mutex_lock()
function will busy-wait on the mutex lock for the specified
number of iterations before blocking the thread, unless the lock is acquired sooner. Larger
spin values would be appropriate for mutexes associated with longer critical sections.
PTHREAD_MUTEX_SPINONLY_NP
Inhibits blocking on the mutex lock altogether. The
pthread_mutex_lock()
function will
busy-wait on the mutex lock until it is acquired.
PTHREAD_MUTEX_SPINDEFAULT_NP
Uses a built-in default value for the number of busy-wait iterations.
Attribute: yield
Note that the yield attribute is not a per-mutex attribute, but is process-wide. That is, it affects the
behavior of all mutexes.
The yield attribute specifies, for the
pthread_mutex_lock()
busy-wait, how frequently the processor
should be yielded (via
sched_yield()
), allowing other threads to execute.
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 attempt-
ing the lock may allow the thread holding the lock to reach the point at which it can release the lock.
However, 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.
Mutex performance enhancement can also be achieved if the implementation does not have to strictly
adhere to the POSIX requirements for acquisition of mutexes by real-time threads. By calling the
pthread_mutexattr_disable_handoff_np()
function or the
pthread_mutex_disable_handoff_np()
function, these requirements will not be strictly
imposed, and the implementation can provide better mutex performance.
The
pthread_mutexattr_disable_handoff_np()
function enables performance improvement
for a specific mutex. This must be called after initializing the mutex attribute.
The
pthread_mutex_disable_handoff_np()
function enables performance improvement for all
mutexes in the process, and must be called by the initial thread before any other threads are created.
RETURN VALUE
pthread_mutexattr_setspin_np(), pthread_mutexattr_getspin_np()
,
pthread_mutex_setyieldfreq_np(), pthread_mutex_getyieldfreq_np()
,
pthread_mutexattr_disable_handoff_np()
, and
pthread_mutex_disable_handoff_np()
return the following values:
0 Successful completion.
<>0 Failure. The returned value is an error number defined in the ERRORS section. (The errno vari-
able is not set).
ERRORS
If an error is detected,
pthread_mutexattr_setspin_np(),
pthread_mutexattr_getspin_np(), pthread_mutex_setyieldfreq_np(), and
pthread_mutex_getyieldfreq_np() return one of the following error numbers.
[EINVAL] The value specified by attr, spin,oryield is invalid.
Section 3812 Hewlett-Packard Company 2 HP-UX 11i Version 2: September 2004