pthread_mutexattr_getpshared.3t (2010 09)

p
pthread_mutexattr_getpshared(3T) pthread_mutexattr_getpshared(3T)
(Pthread Library)
NAME
pthread_mutexattr_getpshared(), pthread_mutexattr_setpshared(), pthread_mutexattr_gettype(),
pthread_mutexattr_settype() - get and set the process-shared attribute and type attribute
SYNOPSIS
#include <pthread.h>
int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr,
int pshared);
int pthread_mutexattr_getpshared(const pthread_mutexattr_t
*__restrict attr, int *__restrict pshared);
int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type);
int pthread_mutexattr_gettype(const pthread_mutexattr_t
*__restrict attr, int *__restrict type);
PARAMETERS
attr Pointer to the mutex attributes object whose attributes are to be set/retrieved.
pshared This parameter either specifies the new value of the process-shared attribute (set func-
tion) or points to the memory location where the process-shared attribute of attr is to be
returned (get function).
type This parameter either specifies the new value of the type attribute (set function) or points
to the memory location where the type attribute of attr is to be returned (get function).
DESCRIPTION
The attributes object attr must have been previously initialized with the function
pthread_mutexattr_init()
before these functions are called.
ATTRIBUTE: pshared
Mutexes can be used by threads only within a process or shared by threads in multiple processes. The
process-shared attribute in a mutex attributes object describes who may use the mutex. The legal values
for the process-shared attribute are:
PTHREAD_PROCESS_SHARED
This option permits a mutex to be operated upon by any thread that has access to the memory
where the mutex is allocated. The application is responsible for allocating the mutex in
memory that multiple processes can access.
PTHREAD_PROCESS_PRIVATE
The mutex can be operated upon only by threads created within the same process as the
thread that initialized the mutex. If threads of differing processes attempt to operate on such
mutex, the behavior is undefined.
The default value of process-shared is
PTHREAD_PROCESS_PRIVATE.
pthread_mutexattr_setpshared() is used to set the process-shared attribute in attr . The new
value of the process-shared attribute of attr is set to the value specified in the pshared parameter.
pthread_mutexattr_getpshared() retrieves the value of the process-shared attribute from attr .
The value of the process-shared attribute of attr is returned in the pshared parameter.
ATTRIBUTE: type
Mutexes can be created with four different types. The type of a mutex is contained in the type attribute of
the mutex attributes object. Valid values for the type attribute are:
PTHREAD_MUTEX_NORMAL
This type of mutex does not provide deadlock detection. A thread attempting to relock this
mutex without first unlocking it shall deadlock. An error is not returned to the caller.
Attempting to unlock a mutex locked by a different thread results in undefined behavior.
Attempting to unlock an unlocked mutex results in undefined behavior.
PTHREAD_MUTEX_ERRORCHECK
This type of mutex provides error checking. An owner field is maintained. Only the mutex
lock owner shall successfully unlock this mutex. A thread attempting to relock this mutex
shall return with an error. A thread attempting to unlock a mutex locked by a different thread
shall return with an error. A thread attempting to unlock an unlocked mutex shall return
with an error. This type of mutex is useful for debugging.
HP-UX 11i Version 3: September 2010 1 Hewlett-Packard Company 1

Summary of content (4 pages)