Content-type: text/html Man page of pthread_mutexattr_getrobust_np

pthread_mutexattr_getrobust_np

Section: Standard C Library Functions (3C)
Updated: 5 Jun 2007
Index Return to Main Contents
 

NAME

pthread_mutexattr_getrobust_np, pthread_mutexattr_setrobust_np - get or set robustness attribute of mutex attribute object  

SYNOPSIS

cc -mt [ flag... ] file... -lpthread [ library... ]
#include <pthread.h> 

int pthread_mutexattr_getrobust_np(const pthread_mutexattr_t *attr,
    int *robustness);

int pthread_mutexattr_setrobust_np(pthread_mutexattr_t *attr,
    int robustness);

 

DESCRIPTION

The pthread_mutexattr_setrobust_np() and pthread_mutexattr_getrobust_np() functions set and get the robustness attribute of a mutex attribute object pointed to by attr that was previously created by the function pthread_mutexattr_init(3C).

The robustness attribute defines the behavior when the owner of a mutex dies. The value of robustness could be either PTHREAD_MUTEX_ROBUST_NP or PTHREAD_MUTEX_STALLED_NP, which are defined by the header <pthread.h>. The default value of the robustness attribute is PTHREAD_MUTEX_STALLED_NP.

When the owner of a mutex with the PTHREAD_MUTEX_STALLED_NP robustness attribute dies, all future calls to pthread_mutex_lock(3C) for this mutex will be blocked from progress in an unspecified manner.

When the owner of a mutex with the PTHREAD_MUTEX_ROBUST_NP robustness attribute dies, or when the process containing such a locked mutex unmaps the memory containing the mutex or performs one of the exec(2) functions, the mutex is unlocked. The next owner of this mutex acquires it with an error value of EOWNERDEAD. Note that the application must always check the return value from pthread_mutex_lock() for a mutex initialized with the PTHREAD_MUTEX_ROBUST_NP robustness attribute. The new owner of this mutex should then attempt to make the state protected by the mutex consistent, since this state could have been left inconsistent when the last owner died. If the new owner is able to make the state consistent, it should call pthread_mutex_consistent_np(3C) for the mutex and then unlock the mutex. If for any reason the new owner is not able to make the state consistent, it should not call pthread_mutex_consistent_np() for the mutex, but should simply unlock the mutex. In the latter scenario, all waiters will be awakened and all subsequent calls to pthread_mutex_lock() will fail in acquiring the mutex with an error value of ENOTRECOVERABLE. If the thread that acquired the lock with EOWNERDEAD dies, the next owner will acquire the lock with an error value of EOWNERDEAD.

The mutex memory must be zeroed before first initialization. Any thread in any process interested in the robust lock can call pthread_mutex_init(3C) to potentially initialize it, provided that all such callers of pthread_mutex_init() specify the same set of attributes in their attribute structures. In this situation, if pthread_mutex_init() is called on a previously initialized robust mutex, it will not reinitialize the mutex and will return the error value EBUSY. If pthread_mutex_init() is called on a previously initialized robust mutex, and if the caller specifies a different set of attributes from those already in effect for the mutex, it will not reinitialize the mutex and will return the error value EINVAL.  

RETURN VALUES

Upon successful completion, the pthread_mutexattr_getrobust_np() and pthread_mutexattr_setrobust_np() functions return 0. Otherwise, an error number is returned to indicate the error.  

ERRORS

The pthread_mutexattr_getrobust_np() and pthread_mutexattr_setrobust_np() functions will fail if:

EINVAL

The value specified by attr or robustness is invalid.

 

ATTRIBUTES

See attributes(5) for descriptions of the following attributes:

ATTRIBUTE TYPEATTRIBUTE VALUE

MT-Level MT-Safe

 

SEE ALSO

pthread_mutex_init(3C), pthread_mutex_lock(3C), pthread_mutex_consistent_np(3C), pthread_mutexattr_getpshared(3C), attributes(5), mutex(5), standards(5)


 

Index

NAME
SYNOPSIS
DESCRIPTION
RETURN VALUES
ERRORS
ATTRIBUTES
SEE ALSO

This document was created by man2html, using the manual pages.
Time: 02:37:18 GMT, October 02, 2010