pthread_mutexattr_getprotocol or pthread_mutexattr_setprotocol Subroutine

Purpose

Gets and sets the protocol attribute of the mutex attributes object.

Syntax

#include <pthread.h>

int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *
       restrict attr, int *restrict protocol);
int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr,
       int protocol); 

Description

The pthread_mutexattr_getprotocol subroutine and pthread_mutexattr_setprotocol subroutine get and set the protocol parameter of a mutex attributes object pointed to by the attr parameter, which was previously created by the pthread_mutexattr_init subroutine.

The protocol attribute defines the protocol to be followed in utilizing mutexes. The value of the protocol parameter can be one of the following, which are defined in the pthread.h header file:
  • PTHREAD_PRIO_NONE
  • PTHREAD_PRIO_INHERIT
  • PTHREAD_PRIO_PROTECT

When a thread owns a mutex with the PTHREAD_PRIO_NONE protocol attribute, its priority and scheduling are not affected by its mutex ownership.

When a thread is blocking higher priority threads because of owning one or more mutexes with the PTHREAD_PRIO_INHERIT protocol attribute, it executes at the higher of its priority or the priority of the highest priority thread waiting on any of the mutexes owned by this thread and initialized with this protocol.

When a thread owns one or more mutexes initialized with the PTHREAD_PRIO_PROTECT protocol, it executes at the higher of its priority or the highest of the priority ceilings of all the mutexes owned by this thread and initialized with this attribute, regardless of whether other threads are blocked on any of these mutexes. Privilege checking is necessary when the mutex priority ceiling is more favored than current thread priority and the thread priority must be changed. The pthread_mutex_lock subroutine does not fail because of inappropriate privileges. Locking succeeds in this case, but no boosting is performed.

While a thread is holding a mutex which has been initialized with the PTHREAD_PRIO_INHERIT or PTHREAD_PRIO_PROTECT protocol attributes, it is not subject to being moved to the tail of the scheduling queue at its priority in the event that its original priority is changed, such as by a call to the sched_setparam subroutine. Likewise, when a thread unlocks a mutex that has been initialized with the PTHREAD_PRIO_INHERIT or PTHREAD_PRIO_PROTECT protocol attributes, it is not subject to being moved to the tail of the scheduling queue at its priority in the event that its original priority is changed.

If a thread simultaneously owns several mutexes initialized with different protocols, it executes at the highest of the priorities that it would have obtained by each of these protocols.

When a thread makes a call to the pthread_mutex_lock subroutine, the mutex was initialized with the protocol attribute having the value PTHREAD_PRIO_INHERIT, when the calling thread is blocked because the mutex is owned by another thread, that owner thread inherits the priority level of the calling thread as long as it continues to own the mutex. The implementation updates its execution priority to the maximum of its assigned priority and all its inherited priorities. Furthermore, if this owner thread itself becomes blocked on another mutex, the same priority inheritance effect shall be propagated to this other owner thread, in a recursive manner.

Behavior prior to AIX® 5.3 is maintained under the non-POSIX protocol PTHREAD_PRIO_DEFAULT.

Return Values

Upon successful completion, the pthread_mutexattr_getprotocol subroutine and the pthread_mutexattr_setprotocol subroutine return zero; otherwise, an error number shall be returned to indicate the error.

Error Codes

The pthread_mutexattr_setprotocol subroutine fails if:
Item Description
ENOTSUP The value specified by the protocol parameter is an unsupported value.
The pthread_mutexattr_getprotocol subroutine and pthread_mutexattr_setprotocol subroutine can fail if:
Item Description
EINVAL The value specified by the attr parameter or the protocol parameter is invalid.
ENOSYS This function is not supported (draft 7).
ENOTSUP This function is not supported together with checkpoint/restart.
EPERM The caller does not have the privilege to perform the operation in a strictly standards conforming environment where environment variable XPG_SUS_ENV=ON.