pthread_rwlock_init() — Initialize a read or write lock object
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
z/OS UNIX |
both | POSIX(ON) |
Format
#define _OPEN_THREADS
#include <pthread.h>
int pthread_rwlock_init(pthread_rwlock_t *rwlock, pthread_rwlockattr_t *attr);
pthread_rwlock_t rwlock=PTHREAD_RWLOCK_INITIALIZER;
#define _UNIX03_THREADS
#include <pthread.h>
int pthread_rwlock_init(pthread_rwlock_t * __restrict__rwlock,
const pthread_rwlockattr_t * __restrict__attr);
General description
The pthread_rwlock_init() function creates a read or write lock, referenced by rwlock, with attributes specified by attr. If attr is NULL, the default read or write lock attribute (PTHREAD_PROCESS_PRIVATE) is used. Once initialized, the lock can be used any number of times without being reinitialized. Upon successful initialization, the state of the read or write lock becomes initialized and unlocked.
In cases where default read or write lock attributes are appropriate, the macro PTHREAD_RWLOCK_INITIALIZER can be used to initialize read or write locks that are statically allocated. The effect is equivalent to dynamic initialization by a call to pthread_rwlock_init() with parameter attr specified as NULL, except that no error checking is done.
Returned value
If successful, pthread_rwlock_init() returns 0, and the state of the read or write lock becomes initialized and unlocked.
- Error Code
- Description
- EAGAIN
- The system lacked necessary resources (other than memory) to initialize another read or write lock.
- EINVAL
- The value specified by attr is not valid.
- ENOMEM
- There is not enough memory to initialize the read or write lock.
- EPERM
- The caller does not have the privilege to perform the operation.
Special behavior for Single UNIX Specification, Version 3: If unsuccessful, pthread_rwlock_init() returns an error number to indicate the error.
Related information
- pthread.h
- pthread_rwlock_destroy() — Destroy a read or write lock object
- pthread_rwlock_rdlock() — Wait for a lock on a read or write lock object
- pthread_rwlock_tryrdlock() — Attempt to lock a read or write lock object for reading
- pthread_rwlock_trywrlock() — Attempt to lock a read or write lock object for writing
- pthread_rwlock_unlock() — Unlock a read or write lock object
- pthread_rwlock_wrlock() — Wait for a lock on a read or write lock object for writing