pthread_mutexattr_getrobust_np, pthread_mutexattr_setrobust_np - get or set robustness attribute of mutex attribute object
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);
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.
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.
The pthread_mutexattr_getrobust_np() and pthread_mutexattr_setrobust_np() functions will fail if:
EINVAL
See attributes(5) for descriptions of the following attributes:
|
pthread_mutex_init(3C), pthread_mutex_lock(3C), pthread_mutex_consistent_np(3C), pthread_mutexattr_getpshared(3C), attributes(5), mutex(5), standards(5)
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |