pthread_mutexattr_getspin_np.3t (2010 09)

p
pthread_mutexattr_getspin_np(3T) pthread_mutexattr_getspin_np(3T)
(Pthread Library)
NAME
pthread_mutexattr_getspin_np(), pthread_mutexattr_setspin_np(), pthread_mutex_getyieldfreq_np(),
pthread_mutex_setyieldfreq_np(), pthread_mutexattr_disable_handoff_np(),
pthread_mutex_disable_handoff_np() - get and set mutex spin and yield frequency attributes; disable
mutex-specific or process-wide mutex handoff mode
SYNOPSIS
#include <pthread.h>
int pthread_mutexattr_setspin_np(
pthread_mutexattr_t *attr,
int spin
);
int pthread_mutexattr_getspin_np(
const pthread_mutexattr_t *attr,
int *spin
);
int pthread_mutex_setyieldfreq_np(
int yield
);
int pthread_mutex_getyieldfreq_np(
int *yield
);
int pthread_mutexattr_disable_handoff(
pthread_mutexattr_t *attr
);"
int pthread_mutex_disable_handoff_np();
PARAMETERS
attr Pointer to the mutex attributes object whose attributes are to be set/retrieved.
spin This parameter either specifies the new value of the spin attribute (set function) or points to
the memory location where the spin attribute of attr is to be returned (get function).
yield This parameter either specifies the new value of the yield frequency process-wide attribute (set
function) or points to the memory location where the yield frequency process-wide attribute is
to be returned (get function).
DESCRIPTION
These attributes are used to tune the mutex locking behavior for optimized application performance on
multiprocessor systems.
For
pthread_mutexattr_setspin_np(),
pthread_mutexattr_getspin_np() and
pthread_mutexattr_disable_handoff_np()
the attributes object attr must have previously
been initialized with the function
pthread_mutexattr_init() before these functions are called.
Attribute: spin
Mutexes can be initialized with a spin value which is used by
pthread_mutex_lock() for busy-wait
iterations on the mutex lock. It is effective only on multiprocessor systems. It is ignored on uniprocessor
systems.
For bound threads, the procedure to block on a busy mutex is quite costly. On a multiprocessor system,
the thread holding the mutex may be a few instruction cycles away from releasing it. By performing a
brief busy-wait before actually blocking, the lock path can avoid a great deal of overhead in these situa-
tions.
For many applications, these situations are not rare. Consider a mutex used to protect a short sequence
of code (e.g., to increment a counter). The mutex is held only for a few instruction cycles (plus the func-
tion call overhead for
pthread_mutex_unlock()).
The ability to set the spin attribute allows the application writer to adjust the busy-wait to suit the dura-
tion of the common-case critical section protected by each mutex.
HP-UX 11i Version 3: September 2010 1 Hewlett-Packard Company 1

Summary of content (4 pages)