Locks a read-write lock for writing.
#include <pthread.h>
#include <time.h>
int pthread_rwlock_timedwrlock(pthread_rwlock_t *restrict rwlock,
const struct timespec *restrict abs_timeout);
The pthread_rwlock_timedwrlock() function applies a write lock to the read-write lock referenced by rwlock as in the pthread_rwlock_wrlock() function. However, if the lock cannot be acquired without waiting for other threads to unlock the lock, this wait terminates when the specified timeout expires. The timeout expires when the absolute time specified by abs_timeout passes—as measured by the clock on which timeouts are based (that is, when the value of that clock equals or exceeds abs_timeout)—or when the absolute time specified by abs_timeout has already been passed at the time of the call.
If the Timers option is supported, the timeout is based on the CLOCK_REALTIME clock; if the Timers option is not supported, the timeout is based on the system clock as returned by the time() function.
The resolution of the timeout matches the resolution of the clock on which it is based. The timespec data type is defined in the <time.h> header.
The function never fails with a timeout if the lock can be acquired immediately. The validity of the abs_timeout parameter does not need to be checked if the lock can be immediately acquired.
If a signal that causes a signal handler to be executed is delivered to a thread that is blocked on a read-write lock through a call to pthread_rwlock_timedwrlock(), the thread resumes waiting for the lock (as if it were not interrupted) after the signal handler returns.
The calling thread can deadlock if it holds the read-write lock at the time the call is made. The results are undefined if this function is called with an uninitialized read-write lock.
The pthread_rwlock_timedwrlock() function is part of the Threads and Timeouts options and do not need to be provided on all implementations.
The pthread_rwlock_timedwrlock() function returns 0 if the lock for writing on the read-write lock object referenced by rwlock is acquired. Otherwise, an error number is returned to indicate the error.
The pthread_rwlock_timedrdlock() function fails if:
Item | Description |
---|---|
ETIMEDOUT | The lock could not be acquired before the specified timeout expired. |
The pthread_rwlock_timedrdlock() function might fail if:
Item | Description |
---|---|
EDEADLK | The calling thread already holds the rwlock. |
EINVAL | The value specified by rwlock does not refer to an initialized read-write lock object, or the abs_timeout nanosecond value is less than 0 or greater than or equal to 1000 million. |
This function does not return an error code of EINTR.