pthread_rwlock_init() — Initialize a read or write lock object

Standards

Standards / Extensions C or C++ Dependencies

z/OS UNIX
Single UNIX Specification, Version 3

both

POSIX(ON)
OS/390 V2R7

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;
SUSV3:
#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.

Note: Although the SUSv3 standard does not specify a static initializer for read or write locks, the implementation-defined macro PTHREAD_RWLOCK_INITIALIZER_NP may be used for that purpose. It is functionally equivalent in the SUSv3 context to the PTHREAD_RWLOCK_INITIALIZER macro.

Returned value

If successful, pthread_rwlock_init() returns 0, and the state of the read or write lock becomes initialized and unlocked.

If unsuccessful, pthread_rwlock_init() returns -1 and sets errno to one of the following values:
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