pthread_mutexattr_getrobust and pthread_mutexattr_setrobust Subroutine

Purpose

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

Library

Threads Library (libpthreads.a)

Syntax

#include <pthread.h>
int pthread_mutexattr_getrobust(const pthread_mutexattr_t *restrict attr, int *restrict robust);
int pthread_mutexattr_setrobust(pthread_mutexattr_t *attr, int  robust);

Description

The pthread_mutexattr_getrobust subroutine obtains the value of the robust attribute from the attributes object that is specified by the attr parameter. The pthread_mutexattr_setrobust subroutine sets the value of the robust attribute in an initialized attributes object that is specified by the attr parameter.

The robust attribute can have the value PTHREAD_MUTEX_STALLED or PTHREAD_MUTEX_ROBUST, and these values are defined in the pthread.h header file. The default value is PTHREAD_MUTEX_STALLED.

When a thread that holds the mutex terminates while the robust attribute is set to PTHREAD_MUTEX_STALLED, and another thread attempts to acquire the mutex, no action is performed.

When a thread that holds the mutex terminates while the robust attribute is set to PTHREAD_MUTEX_ROBUST, and the process-shared attribute is set to PTHREAD_PROCESS_SHARED, the next thread that attempts to get the mutex is notified about the termination. The notified thread becomes the new mutex owner and the protected state of the mutex is now marked as inconsistent.

When the protected state of a robust mutex is inconsistent, the pthread_mutex_consistent subroutine can be used to mark the protected state of the robust mutex as consistent.

When the protected state of a robust mutex is inconsistent, a call to the pthread_mutex_unlock subroutine, without a call to the pthread_mutex_consistent subroutine, marks the protected state of the robust mutex as permanently unusable. In this case, a call to the pthread_mutex_destroy subroutine is the only permissible operation on the robust mutex.

Parameters

Item Description
attr Specifies the mutex attributes object.
robust Indicates the object that stores the value of the robust attribute.

Return Values

On successful completion, the pthread_mutexattr_setrobust subroutine returns a value of zero (0). Otherwise, an error code is returned to indicate the error.

On successful completion, the pthread_mutexattr_getrobust subroutine returns a value of zero (0). The subroutine stores the value of the robust attribute for the attr parameter into an object that is specified by the robust attribute. Otherwise, an error code is returned to indicate the error.

Error Codes

The pthread_mutexattr_getrobust subroutine or the pthread_mutexattr_setrobust subroutine can fail because of the following error:

Item Description
EINVAL The value that is specified by the attr parameter is invalid. For the pthread_mutexattr_setrobust subroutine, this error code can also mean that the new value that is specified for the robust attribute is outside the range of permissible values.

The pthread_mutexattr_getrobust subroutine or the pthread_mutexattr_setrobust subroutine does not return the EINTR error code.