pthread_rwlock_wrlock() — Wait for a lock on a read or write lock object for writing

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_wrlock(pthread_rwlock_t *rwlock);
SUSV3:
#define _UNIX03_THREADS
#include <pthread.h>

int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);

General description

The pthread_rwlock_wrlock() function applies a write lock to the read or write lock referenced by rwlock. The calling thread acquires the write lock if no other thread (reader or writer) holds the read or write lock rwlock. Otherwise, the thread blocks (that is, does not return from the pthread_rwlock_wrlock() call) until it can acquire 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. It will block and wait until there are no writers holding or waiting for the read or write lock. If the thread already holds read or write lock for either read or write then a deadlock errno will be returned.

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_wrlock() returns 0.

If unsuccessful, pthread_rwlock_wrlock() returns -1 and sets errno to one of the following values:
Error Code
Description
EDEADLK
The current thread already owns the read or write lock for writing or reading.
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_wrlock() returns an error number to indicate the error.

Related information