Standards / Extensions | C or C++ | Dependencies |
---|---|---|
z/OS UNIX |
both | POSIX(ON) |
#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);
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).
If successful, pthread_rwlock_tryrdlock() returns 0.
Special behavior for Single UNIX Specification, Version 3: If unsuccessful, pthread_rwlock_tryrdlock() returns an error number to indicate the error.