The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group

 NAME

pthread_mutexattr_setprotocol, pthread_mutexattr_getprotocol - set and get protocol attribute of mutex attribute object (REALTIME THREADS)

 SYNOPSIS



#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

The pthread_mutexattr_setprotocol() and pthread_mutexattr_getprotocol() functions, respectively, set and get the protocol attribute of a mutex attribute object pointed to by attr which was previously created by the function pthread_mutexattr_init().

The protocol attribute defines the protocol to be followed in utilising mutexes. The value of protocol may be one of PTHREAD_PRIO_NONE, PTHREAD_PRIO_INHERIT or PTHREAD_PRIO_PROTECT, which are defined by the header <pthread.h>.

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 initialised with this protocol.

When a thread owns one or more mutexes initialised 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 initialised 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 initialised 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 initialised 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 initialised 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 initialised 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 VALUE

Upon successful completion, the pthread_mutexattr_setprotocol() and pthread_mutexattr_getprotocol() functions return zero. Otherwise, an error number is returned to indicate the error.

 ERRORS

The pthread_mutexattr_setprotocol() and pthread_mutexattr_getprotocol() functions will fail if:
[ENOSYS]
Neither one 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.

The pthread_mutexattr_setprotocol() and pthread_mutexattr_getprotocol() functions may fail if:

[EINVAL]
The value specified by attr ro protocol is invalid.
[EPERM]
The caller does not have the privilege to perform the operation.

 EXAMPLES

None.

 APPLICATION USAGE

None.

 FUTURE DIRECTIONS

None.

 SEE ALSO

pthread_create(), pthread_mutex_init(), pthread_cond_init(), <pthread.h>.

DERIVATION

Derived from the POSIX Threads Extension (1003.1c-1995)

UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]