pthread_rwlock_attr_setfavorwriters_np or pthread_rwlock_attr_getfavorwriters_np Subroutine
Purpose
Sets or returns a read/write lock attribute that enables the pthread library to specify the preference while scheduling the threads to get the read/write lock in write mode.
Library
Threads library (libthreads.a)
Syntax
#define PTHREAD_RWLOCK_FAVORREADERS 0
#define PTHREAD_RWLOCK_FAVORWRITERS 1
#include <pthread.h>
int pthread_rwlock_attr_setfavorwriters_np(pthread_rwlockattr_t *user_attribute_structure,
int favor_attribute)
int pthread_rwlock_attr_getfavorwrites_np(pthread_rwlockattr_t *user_attribute_structure,
int *return_attribute)
Description
The pthread_rwlock_attr_setfavorwriters_np subroutine can be used by an application to initialize the attributes of a read/write lock. You can specify the pthread library to prioritize the scheduling of the threads that requires the read/write lock in write mode. When the pthread library schedules the writer-threads (threads that write data) to get the read/write lock in write mode, the pthread library does not support recursion by threads that are holding a the read/write lock in read mode. Unexpected results can occur when the threads hold a read/write lock in the read mode more than once.
The pthread_rwlock_attr_setfavorwriters_np subroutine sets an attribute to choose writer-threads or reader-threads (threads that need to read data) depending on the value of the favor_attribute attribute that is specified in the subroutine. When the favor_attribute attribute is passed to the pthread_rwlock_init subroutine, the initialized read/write lock considers the specified preference in the attribute structure.
The pthread_rwlock_attr_getfavorwriters_np subroutine returns the current preference that is set in the read/write lock attribute structure. By default, the reader-threads are preferred over writer-threads to get a read/write lock.
Parameters
- favor_attribute
- Indicates the pthread library to prioritize a writer-thread or a reader-thread to get a read/write lock.
- return_attribute
- Returns the specified value in the favor_attribute parameter from the attribute structure of the read/write lock.
Return Values
If the operation is successful, the pthread_rwlock_attr_setfavorwriters_np and pthread_rwlock_attr_getfavorwriters_np subroutines return zero. Otherwise, a number is returned to indicate the error.
Error Codes
- ENOMEM
- Insufficient memory to initialize the read/write lock attributes object.
- EINVAL
- Invalid parameters.