pthread_rwlock_rdlock() — Wait for a lock on 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_rdlock(pthread_rwlock_t *rwlock);
SUSV3:
#define _UNIX03_THREADS
#include <pthread.h>

int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);

General description

The pthread_rwlock_rdlock() function applies a read lock to the read or write lock referenced by rwlock. The calling thread acquires the read lock if a writer does not hold the lock and there are no writers blocked on the lock. In z/OS® UNIX, the calling thread does not acquire the lock when a writer does not hold the lock and there are writers waiting for the lock unless the thread already held rwlock for read. It will block and wait until there are no writers holding or waiting for the read or write lock. If a writer holds the lock, the calling thread will not acquire the read lock. If the read lock is not acquired, the calling thread blocks (that is, it does not return from the pthread_rwlock_rdlock() call) until it can acquire the lock.

A thread may hold multiple concurrent read locks on rwlock (that is successfully call the pthread_rwlock_rdlock() function n times). If so, the thread must perform matching unlocks (that is, it must call the pthread_rwlock_unlock() function n times). Read/write locks are used to protect shared resources.

Note: If a thread owns locks at the time it is terminated then z/OS UNIX will release those locks.

Returned value

If successful, pthread_rwlock_rdlock() returns 0.

If unsuccessful, pthread_rwlock_rdlock() returns -1 and sets errno to one of the following values:
Error Code
Description
EAGAIN
The read lock could not be acquired because the maximum number of read locks for rwlock has been exceeded. This errno will only occur in the shared path.
EDEADLK
The current thread already owns the read or write lock for writing.
EINVAL
The value specified by rwlock is not valid.
ENOMEM
There is not enough memory to acquire a lock. This errno will only occur in the private path.

Special behavior for Single UNIX Specification, Version 3: If unsuccessful, pthread_rwlock_rdlock() returns an error number to indicate the error.

Related information