HP-UX Reference Volume 4 of 5 > pmutexattr_[gs]etpshared(3T)Pthread Library |
|
NAMEpthread_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 *attr, int *pshared); int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type); int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *type); PARAMETERS
DESCRIPTIONThe attributes object attr must have been previously initialized with the function pthread_mutexattr_init() before these functions are called. ATTRIBUTE: psharedMutexes 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:
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: typeMutexes 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:
The default value of the type attribute is PTHREAD_MUTEX_DEAFULT. pthread_mutexattr_settype() is used to set the type attribute in attr. The new value of the type attribute of attr is set to the value specified in the type parameter. pthread_mutexattr_gettype() retrieves the value of the type attribute from attr. The value of the type attribute of attr is returned in the type parameter. Never use a PTHREAD_MUTEX_RECURSIVE mutex with condition variables because the implicit unlock performed for a pthread_cond_wait() or pthread_cond_timedwait() may not actually release the mutex if it had been locked multiple times. If this situation happens, no other thread can satisfy the condition of the predicate. RETURN VALUEUpon successful completion, pthread_mutexattr_getpshared(), pthread_mutexattr_setpshared(), pthread_mutexattr_gettype(), and pthread_mutexattr_settype() return zero. Otherwise, an error number is returned to indicate the error (the errno variable is not set). ERRORSIf any of the following occur, the pthread_mutexattr_getpshared() and pthread_mutexattr_setpshared() functions return the corresponding error number:
For each of the following conditions, if the condition is detected, the pthread_mutexattr_getpshared(), pthread_mutexattr_setpshared(), pthread_mutexattr_gettype(), and pthread_mutexattr_settype() functions return the corresponding error number:
WARNINGSIf a mutex is created with the process-shared attribute defined as PTHREAD_PROCESS_SHARED, the cooperating processes should have access to the memory in which the mutex is allocated. |