pthread_rwlock_tryrdlock() — Attempt to lock a read or write lock object for reading
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
z/OS UNIX |
both | POSIX(ON) |
Format
#define _OPEN_THREADS
#include <pthread.h>
int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock);
#define _UNIX03_THREADS
#include <pthread.h>
int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock);
General description
The pthread_rwlock_tryrdlock() function applies a read lock as in the pthread_rwlock_rdlock() function with the exception that the function fails if any thread holds a write lock on rwlock or there are writers blocked on rwlock unless the thread already held rwlock for read. Read/write locks are used to protect shared resources.
If the read or write lock identified by rwlock is locked, pthread_rwlock_tryrdlock() returns immediately.
When there are only read locks on the read or write lock, pthread_rwlock_tryrdlock() will effectively add to the count of the number of times pthread_rwlock_unlock() must be called by the thread to release the mutex (that is, it has the same behavior as a pthread_rwlock_rdlock() function).
Returned value
If successful, pthread_rwlock_tryrdlock() returns 0.
- 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.
- EBUSY
- rwlock could not be acquired because it was already locked.
- 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_tryrdlock() returns an error number to indicate the error.