pthread_mutexattr_setprotocol(3pthread)


pthread_mutexattr_setprotocol, pthread_mutexattr_getprotocol -- set, get protocol attribute of mutex attribute object

Synopsis

   cc [options] -Kthread file
   

#include <pthread.h>

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

Description

pthread_mutexattr_setprotocol and pthread_mutexattr_setprotocol, respectively, set and get the protocol attribute of a mutex attribute object pointed to by attr.

The attr parameter is a pointer to a mutex attribute object previously created by pthread_mutexattr_init.

*protocol defines the protocol to be followed in utilizing mutexes. Valid values for protocol are defined in the header <pthread.h>, and may be one of the following:


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

PTHREAD_PRIO_INHERIT
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.

PTHREAD_PRIO_PROTECT
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 or not.

While a thread is holding a mutex which has been initialized with the PRIO_INHERIT or PRIO_PROTECT protocol attributes, it will not be 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 sched_setparam. Likewise, when a thread unlocks a mutex that has been initialized with the PRIO_INHERIT or PRIO_PROTECT protocol attributes, it will not be 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 will execute at the highest of the priorities that it would have obtained by each of these protocols.

When a thread makes a call to pthread_mutex_lock, if the symbol _POSIX_THREAD_PRIO_INHERIT is defined and 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 will inherit 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 will be propagated to this other owner thread, in a recursive manner.

Return values

pthread_mutexattr_setprotocol and pthread_mutexattr_getprotocol return zero on success. Otherwise, an error number is returned.

Diagnostics

pthread_mutexattr_setprotocol and pthread_mutexattr_getprotocol return the following value if the corresponding condition is detected:

EINVAL
The value specified by attr or protocol is invalid.

ENOSYS
Neither of the options _POSIX_THREAD_PRIO_PROTECT and _POSIX_THREAD_PRIO_INHERIT is defined and the implementation does not support the function.

ENOTSUP
The value specified by protocol is an unsupported value.

EPERM
The caller does not have the privilege to perform the operation.

Standards Compliance

The Single UNIX Specification, Version 2; The Open Group.

References

Intro(3pthread), pthread_create(3pthread), pthread_cond_init(3pthread), pthread_mutex_init(3pthread), pthread(4)
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004